Struct Literal
pub struct Literal { /* private fields */ }
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) -> 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.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.
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(repr: &str) -> Result<Self, LexError>
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> 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>