pub struct TokenSymbol(/* private fields */);Expand description
Represents a token symbol (e.g. “POL”, “ETH”).
Token Symbols can consist of up to 12 capital Latin characters, e.g. “C”, “ETH”, “MIDEN”.
The symbol is stored as a String and can be converted to a Felt encoding via
as_element().
Implementations§
Source§impl TokenSymbol
impl TokenSymbol
Sourcepub const MAX_SYMBOL_LENGTH: usize = 12
pub const MAX_SYMBOL_LENGTH: usize = 12
Maximum allowed length of the token string.
Sourcepub const ALPHABET_LENGTH: u64 = 26
pub const ALPHABET_LENGTH: u64 = 26
The length of the set of characters that can be used in a token’s name.
Sourcepub const MIN_ENCODED_VALUE: u64 = 1
pub const MIN_ENCODED_VALUE: u64 = 1
The minimum integer value of an encoded TokenSymbol.
This value encodes the “A” token symbol.
Sourcepub const MAX_ENCODED_VALUE: u64 = 2481152873203736562
pub const MAX_ENCODED_VALUE: u64 = 2481152873203736562
The maximum integer value of an encoded TokenSymbol.
This value encodes the “ZZZZZZZZZZZZ” token symbol.
Sourcepub fn new_unchecked(symbol: &str) -> Self
pub fn new_unchecked(symbol: &str) -> Self
Constructs a new TokenSymbol from a string, panicking on invalid input.
§Panics
Panics if:
- The length of the provided string is less than 1 or greater than 12.
- The provided token string contains characters that are not uppercase ASCII.
Sourcepub fn new(symbol: &str) -> Result<Self, TokenSymbolError>
pub fn new(symbol: &str) -> Result<Self, TokenSymbolError>
Creates a new TokenSymbol instance from the provided token name string.
§Errors
Returns an error if:
- The length of the provided string is less than 1 or greater than 12.
- The provided token string contains characters that are not uppercase ASCII.
Sourcepub fn as_element(&self) -> Felt
pub fn as_element(&self) -> Felt
Returns the Felt encoding of this token symbol.
The alphabet used in the encoding process consists of the Latin capital letters as defined in the ASCII table, having the length of 26 characters.
The encoding is performed by multiplying the intermediate encoded value by the length of the used alphabet and adding the relative index of the character to it. At the end of the encoding process the length of the initial token string is added to the encoded value.
Relative character index is computed by subtracting the index of the character “A” (65)
from the index of the currently processing character, e.g., A = 65 - 65 = 0,
B = 66 - 65 = 1, ... , Z = 90 - 65 = 25.
Trait Implementations§
Source§impl Clone for TokenSymbol
impl Clone for TokenSymbol
Source§fn clone(&self) -> TokenSymbol
fn clone(&self) -> TokenSymbol
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TokenSymbol
impl Debug for TokenSymbol
Source§impl Display for TokenSymbol
impl Display for TokenSymbol
Source§impl From<&TokenSymbol> for Felt
impl From<&TokenSymbol> for Felt
Source§fn from(symbol: &TokenSymbol) -> Self
fn from(symbol: &TokenSymbol) -> Self
Source§impl From<TokenSymbol> for Felt
impl From<TokenSymbol> for Felt
Source§fn from(symbol: TokenSymbol) -> Self
fn from(symbol: TokenSymbol) -> Self
Source§impl PartialEq for TokenSymbol
impl PartialEq for TokenSymbol
Source§impl TryFrom<&str> for TokenSymbol
impl TryFrom<&str> for TokenSymbol
Source§impl TryFrom<Felt> for TokenSymbol
Decodes a Felt representation of the token symbol into a TokenSymbol.
impl TryFrom<Felt> for TokenSymbol
Decodes a Felt representation of the token symbol into a TokenSymbol.
The alphabet used in the decoding process consists of the Latin capital letters as defined in the ASCII table, having the length of 26 characters.
The decoding is performed by getting the modulus of the intermediate encoded value by the length of the used alphabet and then dividing the intermediate value by the length of the alphabet to shift to the next character. At the beginning of the decoding process the length of the initial token string is obtained from the encoded value. After that the value obtained after taking the modulus represents the relative character index, which then gets converted to the ASCII index.
Final ASCII character index is computed by adding the index of the character “A” (65) to the
index of the currently processing character, e.g., A = 0 + 65 = 65, B = 1 + 65 = 66,
... , Z = 25 + 65 = 90.
impl Eq for TokenSymbol
impl StructuralPartialEq for TokenSymbol
Auto Trait Implementations§
impl Freeze for TokenSymbol
impl RefUnwindSafe for TokenSymbol
impl Send for TokenSymbol
impl Sync for TokenSymbol
impl Unpin for TokenSymbol
impl UnsafeUnpin for TokenSymbol
impl UnwindSafe for TokenSymbol
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more