pub struct FloatLit<B: Buffer> { /* private fields */ }
Expand description
A floating point literal, e.g. 3.14
, 8.
, 135e12
, 27f32
or 1.956e2f64
.
This kind of literal has several forms, but generally consists of a main number part, an optional exponent and an optional type suffix. See the reference for more information.
A leading minus sign -
is not part of the literal grammar! -3.14
are two
tokens in the Rust grammar.
Implementations§
Source§impl<B: Buffer> FloatLit<B>
impl<B: Buffer> FloatLit<B>
Sourcepub fn parse(s: B) -> Result<Self, ParseError>
pub fn parse(s: B) -> Result<Self, ParseError>
Parses the input as a floating point literal. Returns an error if the input is invalid or represents a different kind of literal.
Sourcepub fn number_part(&self) -> &str
pub fn number_part(&self) -> &str
Returns the whole number part (including integer part, fractional part
and exponent), but without the type suffix. If you want an actual
floating point value, you need to parse this string, e.g. with
f32::from_str
or an external crate.
Sourcepub fn integer_part(&self) -> &str
pub fn integer_part(&self) -> &str
Returns the non-empty integer part of this literal.
Sourcepub fn fractional_part(&self) -> Option<&str>
pub fn fractional_part(&self) -> Option<&str>
Returns the optional fractional part of this literal. Does not include
the period. If a period exists in the input, Some
is returned, None
otherwise. Note that Some("")
might be returned, e.g. for 3.
.
Sourcepub fn exponent_part(&self) -> &str
pub fn exponent_part(&self) -> &str
Optional exponent part. Might be empty if there was no exponent part in
the input. Includes the e
or E
at the beginning.
Sourcepub fn type_suffix(&self) -> Option<FloatType>
pub fn type_suffix(&self) -> Option<FloatType>
The optional type suffix.