Struct Literal
pub struct Literal(pub(crate) Literal<Span, Symbol>);
A literal string ("hello"), byte string (b"hello"), C string (c"hello"),
character ('a'), byte character (b'a'), an integer or floating point number
with or without a suffix (1, 1u8, 2.3, 2.3f32).
Boolean literals like true and false do not belong here, they are Idents.
Fields
0: Literal<Span, Symbol>
Implementations
impl Literal
fn new(kind: LitKind, value: &str, suffix: Option<&str>) -> Selffn u8_suffixed(n: u8) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u16_suffixed(n: u16) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u32_suffixed(n: u32) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u64_suffixed(n: u64) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u128_suffixed(n: u128) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn usize_suffixed(n: usize) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i8_suffixed(n: i8) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i16_suffixed(n: i16) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i32_suffixed(n: i32) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i64_suffixed(n: i64) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i128_suffixed(n: i128) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn isize_suffixed(n: isize) -> LiteralCreates a new suffixed integer literal with the specified value.
This function will create an integer like
1u32where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers might not survive round-trips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u8_unsuffixed(n: u8) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u16_unsuffixed(n: u16) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u32_unsuffixed(n: u32) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u64_unsuffixed(n: u64) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn u128_unsuffixed(n: u128) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn usize_unsuffixed(n: usize) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i8_unsuffixed(n: i8) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i16_unsuffixed(n: i16) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i32_unsuffixed(n: i32) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i64_unsuffixed(n: i64) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn i128_unsuffixed(n: i128) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn isize_unsuffixed(n: isize) -> LiteralCreates a new unsuffixed integer literal with the specified value.
This function will create an integer like
1where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations likeLiteral::i8_unsuffixed(1)are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Literals created through this method have the
Span::call_site()span by default, which can be configured with theset_spanmethod below.fn f32_unsuffixed(n: f32) -> LiteralCreates a new unsuffixed floating-point literal.
This constructor is similar to those like
Literal::i8_unsuffixedwhere the float's value is emitted directly into the token but no suffix is used, so it may be inferred to be af64later in the compiler. Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Panics
This function requires that the specified float is finite, for example if it is infinity or NaN this function will panic.
fn f32_suffixed(n: f32) -> LiteralCreates a new suffixed floating-point literal.
This constructor will create a literal like
1.0f32where the value specified is the preceding part of the token andf32is the suffix of the token. This token will always be inferred to be anf32in the compiler. Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Panics
This function requires that the specified float is finite, for example if it is infinity or NaN this function will panic.
fn f64_unsuffixed(n: f64) -> LiteralCreates a new unsuffixed floating-point literal.
This constructor is similar to those like
Literal::i8_unsuffixedwhere the float's value is emitted directly into the token but no suffix is used, so it may be inferred to be af64later in the compiler. Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Panics
This function requires that the specified float is finite, for example if it is infinity or NaN this function will panic.
fn f64_suffixed(n: f64) -> LiteralCreates a new suffixed floating-point literal.
This constructor will create a literal like
1.0f64where the value specified is the preceding part of the token andf64is the suffix of the token. This token will always be inferred to be anf64in the compiler. Literals created from negative numbers might not survive roundtrips throughTokenStreamor strings and may be broken into two tokens (-and positive literal).Panics
This function requires that the specified float is finite, for example if it is infinity or NaN this function will panic.
fn string(string: &str) -> LiteralString literal.
fn character(ch: char) -> LiteralCharacter literal.
fn byte_character(byte: u8) -> LiteralByte character literal.
fn byte_string(bytes: &[u8]) -> LiteralByte string literal.
fn c_string(string: &CStr) -> LiteralC string literal.
fn span(&self) -> SpanReturns the span encompassing this literal.
fn set_span(&mut self, span: Span)Configures the span associated for this literal.
fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span>Returns a
Spanthat is a subset ofself.span()containing only the source bytes in rangerange. ReturnsNoneif the would-be trimmed span is outside the bounds ofself.fn with_symbol_and_suffix<R>(&self, f: impl FnOnce(&str, &str) -> R) -> Rfn with_stringify_parts<R>(&self, f: impl FnOnce(&[&str]) -> R) -> RInvokes the callback with a
&[&str]consisting of each part of the literal's representation. This is done to allow theToStringandDisplayimplementations to borrow references to symbol values, and both be optimized to reduce overhead.fn byte_character_value(&self) -> Result<u8, ConversionErrorKind>Returns the unescaped character value if the current literal is a byte character literal.
fn character_value(&self) -> Result<char, ConversionErrorKind>Returns the unescaped character value if the current literal is a character literal.
fn str_value(&self) -> Result<String, ConversionErrorKind>Returns the unescaped string value if the current literal is a string or a string literal.
fn cstr_value(&self) -> Result<Vec<u8>, ConversionErrorKind>Returns the unescaped string value if the current literal is a c-string or a c-string literal.
fn byte_str_value(&self) -> Result<Vec<u8>, ConversionErrorKind>Returns the unescaped string value if the current literal is a byte string or a byte string literal.
fn u8_value(&self) -> Result<u8, ConversionErrorKind>Returns the unescaped
u8value if the literal is au8or if it's an "unmarked" integer which doesn't overflow.fn u16_value(&self) -> Result<u16, ConversionErrorKind>Returns the unescaped
u16value if the literal is au16or if it's an "unmarked" integer which doesn't overflow.fn u32_value(&self) -> Result<u32, ConversionErrorKind>Returns the unescaped
u32value if the literal is au32or if it's an "unmarked" integer which doesn't overflow.fn u64_value(&self) -> Result<u64, ConversionErrorKind>Returns the unescaped
u64value if the literal is au64or if it's an "unmarked" integer which doesn't overflow.fn u128_value(&self) -> Result<u128, ConversionErrorKind>Returns the unescaped
u128value if the literal is au128or if it's an "unmarked" integer which doesn't overflow.fn i8_value(&self) -> Result<i8, ConversionErrorKind>Returns the unescaped
i8value if the literal is ai8or if it's an "unmarked" integer which doesn't overflow.fn i16_value(&self) -> Result<i16, ConversionErrorKind>Returns the unescaped
i16value if the literal is ai16or if it's an "unmarked" integer which doesn't overflow.fn i32_value(&self) -> Result<i32, ConversionErrorKind>Returns the unescaped
i32value if the literal is ai32or if it's an "unmarked" integer which doesn't overflow.fn i64_value(&self) -> Result<i64, ConversionErrorKind>Returns the unescaped
i64value if the literal is ai64or if it's an "unmarked" integer which doesn't overflow.fn i128_value(&self) -> Result<i128, ConversionErrorKind>Returns the unescaped
i128value if the literal is ai128or if it's an "unmarked" integer which doesn't overflow.fn f16_value(&self) -> Result<f16, ConversionErrorKind>Returns the unescaped
f16value if the literal is af16or if it's an "unmarked" float which doesn't overflow.fn f32_value(&self) -> Result<f32, ConversionErrorKind>Returns the unescaped
f32value if the literal is af32or if it's an "unmarked" float which doesn't overflow.fn f64_value(&self) -> Result<f64, ConversionErrorKind>Returns the unescaped
f64value if the literal is af64or if it's an "unmarked" float which doesn't overflow.
Trait Implementations
impl Clone for Literal
fn clone(&self) -> Literal
impl Debug for Literal
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Display for Literal
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl FromStr for Literal
type Err = LexError;fn from_str(src: &str) -> Result<Self, LexError>
impl ToTokens for Literal
fn to_tokens(&self, tokens: &mut TokenStream)
Auto Trait Implementations
impl !Send for Literal
impl !Sync for Literal
impl Freeze for Literal
impl RefUnwindSafe for Literal
impl Unpin for Literal
impl UnsafeUnpin for Literal
impl UnwindSafe for Literal
Blanket Implementations
impl<T> Any for Literal
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Literal
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Literal
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Literal
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Literal
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RepToTokensExt for Literal
where
T: ToTokens + ?Sized,
impl<T> SizeHint for Literal
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for Literal
impl<T> ToOwned for Literal
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> ToString for Literal
where
T: Display + ?Sized,
fn to_string(&self) -> String
impl<T, U> Into<U> for Literal
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Literal
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Literal
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>