Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Feb 3, 2023
1 parent 98c0ba6 commit fb9aac4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions contracts/utils/ShortStrings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ type ShortString is bytes32;
* into a `ShortString` type that can be used as an immutable variable.
* Strings of arbitrary length can be optimized if they are short enough by
* the addition of a storage variable used as fallback.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
error StringTooLong(string str);
Expand Down

0 comments on commit fb9aac4

Please sign in to comment.