Symbol from a string literal at compile time.
The string must be 32 characters or less and contain only valid symbol characters: a-zA-Z0-9_.
Syntax
Parameters
A string literal containing 1-32 characters. Valid characters are:
- Lowercase letters:
a-z - Uppercase letters:
A-Z - Digits:
0-9 - Underscore:
_
Constraints
- Maximum length: 32 characters
- Valid characters:
a-zA-Z0-9_ - The string must be a literal (not a variable or expression)
Return Value
Returns aSymbol value that can be used at compile time or runtime.
Example
Basic Usage
Using in Contract Storage
Using in Events
Maximum Length Example
Performance
Symbols created withsymbol_short! are:
- Created at compile time (zero runtime overhead)
- Stored efficiently as small integers internally
- Faster to compare than strings
- Ideal for storage keys and event topics
Comparison with Symbol::new
There are two ways to create symbols:symbol_short! when:
- The symbol value is known at compile time
- You want maximum performance
- The string is 32 characters or less
Symbol::new() when:
- The symbol value is computed at runtime
- You need symbols longer than 32 characters
- You need dynamic symbol creation
See Also
Symbol- The Symbol type and runtime creation