pub struct FloatLit<B: Buffer> {
raw: B,
end_integer_part: usize,
end_fractional_part: usize,
end_number_part: usize,
}
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.
Fields§
§raw: B
The whole raw input. The usize
fields in this struct partition this
string. Always true: end_integer_part <= end_fractional_part
.
12_3.4_56e789f32
╷ ╷ ╷
| | └ end_number_part = 13
| └ end_fractional_part = 9
└ end_integer_part = 4
246.
╷╷
|└ end_fractional_part = end_number_part = 4
└ end_integer_part = 3
1234e89
╷ ╷
| └ end_number_part = 7
└ end_integer_part = end_fractional_part = 4
end_integer_part: usize
The first index not part of the integer part anymore. Since the integer part is at the start, this is also the length of that part.
end_fractional_part: usize
The first index after the fractional part.
end_number_part: usize
The first index after the whole number part (everything except type suffix).
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.
Trait Implementations§
impl<B: Copy + Buffer> Copy for FloatLit<B>
impl<B: Eq + Buffer> Eq for FloatLit<B>
impl<B: Buffer> StructuralPartialEq for FloatLit<B>
Auto Trait Implementations§
impl<B> Freeze for FloatLit<B>where
B: Freeze,
impl<B> RefUnwindSafe for FloatLit<B>where
B: RefUnwindSafe,
impl<B> Send for FloatLit<B>where
B: Send,
impl<B> Sync for FloatLit<B>where
B: Sync,
impl<B> Unpin for FloatLit<B>where
B: Unpin,
impl<B> UnwindSafe for FloatLit<B>where
B: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)