pub struct Literal(/* private fields */);Expand description
A literal string ("hello"), byte string (b"hello"), C string (c"hello"),character ('a'), byte character (b'a'), an integer or floating point numberwith or without a suffix (1,1u8,2.3,2.3f32).Boolean literals liketrue andfalse do not belong here, they areIdents.
Implementations§
Source§implLiteral
implLiteral
1.29.0 ·Sourcepub fnu8_suffixed(n:u8) ->Literal
pub fnu8_suffixed(n:u8) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu16_suffixed(n:u16) ->Literal
pub fnu16_suffixed(n:u16) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu32_suffixed(n:u32) ->Literal
pub fnu32_suffixed(n:u32) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu64_suffixed(n:u64) ->Literal
pub fnu64_suffixed(n:u64) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu128_suffixed(n:u128) ->Literal
pub fnu128_suffixed(n:u128) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnusize_suffixed(n:usize) ->Literal
pub fnusize_suffixed(n:usize) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni8_suffixed(n:i8) ->Literal
pub fni8_suffixed(n:i8) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni16_suffixed(n:i16) ->Literal
pub fni16_suffixed(n:i16) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni32_suffixed(n:i32) ->Literal
pub fni32_suffixed(n:i32) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni64_suffixed(n:i64) ->Literal
pub fni64_suffixed(n:i64) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni128_suffixed(n:i128) ->Literal
pub fni128_suffixed(n:i128) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnisize_suffixed(n:isize) ->Literal
pub fnisize_suffixed(n:isize) ->Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso suffixed at the end.Literals created from negative numbers might not survive round-trips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu8_unsuffixed(n:u8) ->Literal
pub fnu8_unsuffixed(n:u8) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu16_unsuffixed(n:u16) ->Literal
pub fnu16_unsuffixed(n:u16) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu32_unsuffixed(n:u32) ->Literal
pub fnu32_unsuffixed(n:u32) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu64_unsuffixed(n:u64) ->Literal
pub fnu64_unsuffixed(n:u64) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnu128_unsuffixed(n:u128) ->Literal
pub fnu128_unsuffixed(n:u128) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnusize_unsuffixed(n:usize) ->Literal
pub fnusize_unsuffixed(n:usize) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni8_unsuffixed(n:i8) ->Literal
pub fni8_unsuffixed(n:i8) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni16_unsuffixed(n:i16) ->Literal
pub fni16_unsuffixed(n:i16) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni32_unsuffixed(n:i32) ->Literal
pub fni32_unsuffixed(n:i32) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni64_unsuffixed(n:i64) ->Literal
pub fni64_unsuffixed(n:i64) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fni128_unsuffixed(n:i128) ->Literal
pub fni128_unsuffixed(n:i128) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnisize_unsuffixed(n:isize) ->Literal
pub fnisize_unsuffixed(n:isize) ->Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1).Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
Literals created through this method have theSpan::call_site()span by default, which can be configured with theset_span methodbelow.
1.29.0 ·Sourcepub fnf32_unsuffixed(n:f32) ->Literal
pub fnf32_unsuffixed(n:f32) ->Literal
Creates a new unsuffixed floating-point literal.
This constructor is similar to those likeLiteral::i8_unsuffixed wherethe float’s value is emitted directly into the token but no suffix isused, so it may be inferred to be af64 later in the compiler.Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
§Panics
This function requires that the specified float is finite, forexample if it is infinity or NaN this function will panic.
1.29.0 ·Sourcepub fnf32_suffixed(n:f32) ->Literal
pub fnf32_suffixed(n:f32) ->Literal
Creates a new suffixed floating-point literal.
This constructor will create a literal like1.0f32 where the valuespecified is the preceding part of the token andf32 is the suffix ofthe token. This token will always be inferred to be anf32 in thecompiler.Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
§Panics
This function requires that the specified float is finite, forexample if it is infinity or NaN this function will panic.
1.29.0 ·Sourcepub fnf64_unsuffixed(n:f64) ->Literal
pub fnf64_unsuffixed(n:f64) ->Literal
Creates a new unsuffixed floating-point literal.
This constructor is similar to those likeLiteral::i8_unsuffixed wherethe float’s value is emitted directly into the token but no suffix isused, so it may be inferred to be af64 later in the compiler.Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
§Panics
This function requires that the specified float is finite, forexample if it is infinity or NaN this function will panic.
1.29.0 ·Sourcepub fnf64_suffixed(n:f64) ->Literal
pub fnf64_suffixed(n:f64) ->Literal
Creates a new suffixed floating-point literal.
This constructor will create a literal like1.0f64 where the valuespecified is the preceding part of the token andf64 is the suffix ofthe token. This token will always be inferred to be anf64 in thecompiler.Literals created from negative numbers might not survive rountrips throughTokenStream or strings and may be broken into two tokens (- and positive literal).
§Panics
This function requires that the specified float is finite, forexample if it is infinity or NaN this function will panic.
1.79.0 ·Sourcepub fnbyte_character(byte:u8) ->Literal
pub fnbyte_character(byte:u8) ->Literal
Byte character literal.
1.29.0 ·Sourcepub fnbyte_string(bytes: &[u8]) ->Literal
pub fnbyte_string(bytes: &[u8]) ->Literal
Byte string literal.
Sourcepub fnsubspan<R:RangeBounds<usize>>(&self, range: R) ->Option<Span>
🔬This is a nightly-only experimental API. (proc_macro_span #54725)
pub fnsubspan<R:RangeBounds<usize>>(&self, range: R) ->Option<Span>
proc_macro_span #54725)Returns aSpan that is a subset ofself.span() containing only thesource bytes in rangerange. ReturnsNone if the would-be trimmedspan is outside the bounds ofself.
Sourcepub fnstr_value(&self) ->Result<String,ConversionErrorKind>
🔬This is a nightly-only experimental API. (proc_macro_value #136652)
pub fnstr_value(&self) ->Result<String,ConversionErrorKind>
proc_macro_value #136652)Returns the unescaped string value if the current literal is a string or a string literal.
Sourcepub fncstr_value(&self) ->Result<Vec<u8>,ConversionErrorKind>
🔬This is a nightly-only experimental API. (proc_macro_value #136652)
pub fncstr_value(&self) ->Result<Vec<u8>,ConversionErrorKind>
proc_macro_value #136652)Returns the unescaped string value if the current literal is a c-string or a c-stringliteral.
Sourcepub fnbyte_str_value(&self) ->Result<Vec<u8>,ConversionErrorKind>
🔬This is a nightly-only experimental API. (proc_macro_value #136652)
pub fnbyte_str_value(&self) ->Result<Vec<u8>,ConversionErrorKind>
proc_macro_value #136652)Returns the unescaped string value if the current literal is a byte string or a byte stringliteral.
Trait Implementations§
1.29.0 ·Source§implDisplay forLiteral
Prints the literal as a string that should be losslessly convertibleback into the same literal (except for possible rounding for floating point literals).
implDisplay forLiteral
Prints the literal as a string that should be losslessly convertibleback into the same literal (except for possible rounding for floating point literals).
1.54.0 ·Source§implFromStr forLiteral
Parse a single literal from its stringified representation.
implFromStr forLiteral
Parse a single literal from its stringified representation.
In order to parse successfully, the input string must not contain anythingbut the literal token. Specifically, it must not contain whitespace orcomments in addition to the literal.
The resulting literal token will have aSpan::call_site() span.
NOTE: some errors may cause panics instead of returningLexError. Wereserve the right to change these errors intoLexErrors later.
Source§implToTokens forLiteral
implToTokens forLiteral
Source§fnto_tokens(&self, tokens: &mutTokenStream)
fnto_tokens(&self, tokens: &mutTokenStream)
proc_macro_totokens #130977)Source§fnto_token_stream(&self) ->TokenStream
fnto_token_stream(&self) ->TokenStream
proc_macro_totokens #130977)Source§fninto_token_stream(self) ->TokenStreamwhere Self:Sized,
fninto_token_stream(self) ->TokenStreamwhere Self:Sized,
proc_macro_totokens #130977)