Struct proc_macro2::Literal
source · [−]pub struct Literal { /* private fields */ }
Expand description
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
Ident
s.
Implementations
sourceimpl Literal
impl Literal
sourcepub fn u8_suffixed(n: u8) -> Literal
pub fn u8_suffixed(n: u8) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn u16_suffixed(n: u16) -> Literal
pub fn u16_suffixed(n: u16) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn u32_suffixed(n: u32) -> Literal
pub fn u32_suffixed(n: u32) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn u64_suffixed(n: u64) -> Literal
pub fn u64_suffixed(n: u64) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn u128_suffixed(n: u128) -> Literal
pub fn u128_suffixed(n: u128) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn usize_suffixed(n: usize) -> Literal
pub fn usize_suffixed(n: usize) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn i8_suffixed(n: i8) -> Literal
pub fn i8_suffixed(n: i8) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn i16_suffixed(n: i16) -> Literal
pub fn i16_suffixed(n: i16) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn i32_suffixed(n: i32) -> Literal
pub fn i32_suffixed(n: i32) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn i64_suffixed(n: i64) -> Literal
pub fn i64_suffixed(n: i64) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn i128_suffixed(n: i128) -> Literal
pub fn i128_suffixed(n: i128) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn isize_suffixed(n: isize) -> Literal
pub fn isize_suffixed(n: isize) -> Literal
Creates a new suffixed integer literal with the specified value.
This function will create an integer like 1u32
where 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 through TokenStream
or 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 the set_span
method
below.
sourcepub fn u8_unsuffixed(n: u8) -> Literal
pub fn u8_unsuffixed(n: u8) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn u16_unsuffixed(n: u16) -> Literal
pub fn u16_unsuffixed(n: u16) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn u32_unsuffixed(n: u32) -> Literal
pub fn u32_unsuffixed(n: u32) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn u64_unsuffixed(n: u64) -> Literal
pub fn u64_unsuffixed(n: u64) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn u128_unsuffixed(n: u128) -> Literal
pub fn u128_unsuffixed(n: u128) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn usize_unsuffixed(n: usize) -> Literal
pub fn usize_unsuffixed(n: usize) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn i8_unsuffixed(n: i8) -> Literal
pub fn i8_unsuffixed(n: i8) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn i16_unsuffixed(n: i16) -> Literal
pub fn i16_unsuffixed(n: i16) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn i32_unsuffixed(n: i32) -> Literal
pub fn i32_unsuffixed(n: i32) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn i64_unsuffixed(n: i64) -> Literal
pub fn i64_unsuffixed(n: i64) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn i128_unsuffixed(n: i128) -> Literal
pub fn i128_unsuffixed(n: i128) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn isize_unsuffixed(n: isize) -> Literal
pub fn isize_unsuffixed(n: isize) -> Literal
Creates a new unsuffixed integer literal with the specified value.
This function will create an integer like 1
where the integer
value specified is the first part of the token. No suffix is
specified on this token, meaning that invocations like
Literal::i8_unsuffixed(1)
are equivalent to
Literal::u32_unsuffixed(1)
. Literals created from negative numbers
may not survive roundtrips through TokenStream
or 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 the set_span
method
below.
sourcepub fn f64_unsuffixed(f: f64) -> Literal
pub fn f64_unsuffixed(f: f64) -> Literal
Creates a new unsuffixed floating-point literal.
This constructor is similar to those like Literal::i8_unsuffixed
where
the float’s value is emitted directly into the token but no suffix is
used, so it may be inferred to be a f64
later in the compiler.
Literals created from negative numbers may not survive round-trips
through TokenStream
or 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.
sourcepub fn f64_suffixed(f: f64) -> Literal
pub fn f64_suffixed(f: f64) -> Literal
Creates a new suffixed floating-point literal.
This constructor will create a literal like 1.0f64
where the value
specified is the preceding part of the token and f64
is the suffix of
the token. This token will always be inferred to be an f64
in the
compiler. Literals created from negative numbers may not survive
round-trips through TokenStream
or 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.
sourcepub fn f32_unsuffixed(f: f32) -> Literal
pub fn f32_unsuffixed(f: f32) -> Literal
Creates a new unsuffixed floating-point literal.
This constructor is similar to those like Literal::i8_unsuffixed
where
the float’s value is emitted directly into the token but no suffix is
used, so it may be inferred to be a f64
later in the compiler.
Literals created from negative numbers may not survive round-trips
through TokenStream
or 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.
sourcepub fn f32_suffixed(f: f32) -> Literal
pub fn f32_suffixed(f: f32) -> Literal
Creates a new suffixed floating-point literal.
This constructor will create a literal like 1.0f32
where the value
specified is the preceding part of the token and f32
is the suffix of
the token. This token will always be inferred to be an f32
in the
compiler. Literals created from negative numbers may not survive
round-trips through TokenStream
or 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.
sourcepub fn byte_string(s: &[u8]) -> Literal
pub fn byte_string(s: &[u8]) -> Literal
Byte string literal.
sourcepub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span>
pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span>
Returns a Span
that is a subset of self.span()
containing only
the source bytes in range range
. Returns None
if the would-be
trimmed span is outside the bounds of self
.
Warning: the underlying proc_macro::Literal::subspan
method is
nightly-only. When called from within a procedural macro not using a
nightly compiler, this method will always return None
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Literal
impl !Send for Literal
impl !Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more