#[non_exhaustive]pub struct IntegerLit<B: Buffer> { /* private fields */ }
Expand description
An integer literal, e.g. 27
, 0x7F
, 0b101010u8
or 5_000_000i64
.
An integer literal consists of an optional base prefix (0b
, 0o
, 0x
),
the main part (digits and underscores), and an optional type suffix
(e.g. u64
or i8
). See the reference for more information.
Note that integer literals are always positive: the grammar does not contain
the minus sign at all. The minus sign is just the unary negate operator,
not part of the literal. Which is interesting for cases like - 128i8
:
here, the literal itself would overflow the specified type (i8
cannot
represent 128). That’s why in rustc, the literal overflow check is
performed as a lint after parsing, not during the lexing stage. Similarly,
IntegerLit::parse
does not perform an overflow check.
Implementations§
Source§impl<B: Buffer> IntegerLit<B>
impl<B: Buffer> IntegerLit<B>
Sourcepub fn parse(input: B) -> Result<Self, ParseError>
pub fn parse(input: B) -> Result<Self, ParseError>
Parses the input as an integer literal. Returns an error if the input is invalid or represents a different kind of literal.
Sourcepub fn value<N: FromIntegerLiteral>(&self) -> Option<N>
pub fn value<N: FromIntegerLiteral>(&self) -> Option<N>
Performs the actual string to int conversion to obtain the integer
value. The optional type suffix of the literal is ignored by this
method. This means N
does not need to match the type suffix!
Returns None
if the literal overflows N
.
Sourcepub fn base(&self) -> IntegerBase
pub fn base(&self) -> IntegerBase
The base of this integer literal.
Sourcepub fn raw_main_part(&self) -> &str
pub fn raw_main_part(&self) -> &str
The main part containing the digits and potentially _
. Do not try to
parse this directly as that would ignore the base!
Sourcepub fn type_suffix(&self) -> Option<IntegerType>
pub fn type_suffix(&self) -> Option<IntegerType>
The type suffix, if specified.
Source§impl IntegerLit<&str>
impl IntegerLit<&str>
Sourcepub fn to_owned(&self) -> IntegerLit<String>
pub fn to_owned(&self) -> IntegerLit<String>
Makes a copy of the underlying buffer and returns the owned version of
Self
.
Trait Implementations§
Source§impl<B: Clone + Buffer> Clone for IntegerLit<B>
impl<B: Clone + Buffer> Clone for IntegerLit<B>
Source§fn clone(&self) -> IntegerLit<B>
fn clone(&self) -> IntegerLit<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more