Struct Literal
struct Literal { ... }
A literal string ("hello"), byte string (b"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.
Implementations
impl Literal
fn 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 may 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_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 may 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_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 may 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_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 may 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_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 may 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_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 may 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_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 may 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_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 may 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_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 may 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_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 may 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_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 may 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_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 may 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 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 may 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 may 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 may 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 may 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 may 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 may 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 may 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 may 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 may 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 may 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 may 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 may 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 f64_unsuffixed(f: 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 may not survive round-trips 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(f: 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 may not survive round-trips 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_unsuffixed(f: 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 may not survive round-trips 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(f: 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 may not survive round-trips 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: &Self) -> SpanReturns the span encompassing this literal.
fn set_span(self: &mut Self, span: Span)Configures the span associated for this literal.
fn subspan<R: RangeBounds<usize>>(self: &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.Warning: the underlying
proc_macro::Literal::subspanmethod is nightly-only. When called from within a procedural macro not using a nightly compiler, this method will always returnNone.
impl Clone for Literal
fn clone(self: &Self) -> Literal
impl Debug for Literal
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Display for Literal
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Freeze for Literal
impl FromStr for Literal
fn from_str(repr: &str) -> Result<Self, LexError>
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
impl<T> Any for Literal
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Literal
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Literal
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Literal
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Literal
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Literal
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for Literal
fn to_string(self: &Self) -> String
impl<T, U> Into for Literal
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Literal
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Literal
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>