pub struct FloatLit<B: Buffer> { /* private fields */ }
Expand description
A floating point literal, e.g. 3.14
, 8.
, 135e12
, 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. Further, 27
and 27f32
are both not float,
but integer literals! Consequently FloatLit::parse
will reject them.
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. Will also
reject decimal integer literals like 23
or 17f32
, in accordance
with the spec.
sourcepub fn number_part(&self) -> &str
pub fn number_part(&self) -> &str
Returns the number part (including integer part, fractional part and
exponent), but without the 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 suffix(&self) -> &str
pub fn suffix(&self) -> &str
The optional suffix. Returns ""
if the suffix is empty/does not exist.
sourcepub fn into_raw_input(self) -> B
pub fn into_raw_input(self) -> B
Returns the raw input that was passed to parse
, potentially owned.