pub struct ParseFloatOptions { /* private fields */ }
parse-floats
only.Expand description
Options to customize parsing floats.
This enables extensive control over how the float is parsed, from control characters like the decimal point and the valid non-finite float representations.
§Examples
use lexical_parse_float::{FromLexicalWithOptions, Options};
use lexical_parse_float::format::STANDARD;
const OPTIONS: Options = Options::builder()
.lossy(true)
.nan_string(Some(b"NaN"))
.inf_string(Some(b"Inf"))
.infinity_string(Some(b"Infinity"))
.build_strict();
let value = "1.2345e300";
let result = f64::from_lexical_with_options::<STANDARD>(value.as_bytes(), &OPTIONS);
assert_eq!(result, Ok(1.2345e300));
let value = "NaN";
let result = f64::from_lexical_with_options::<STANDARD>(value.as_bytes(), &OPTIONS);
assert_eq!(result.map(|x| x.is_nan()), Ok(true));
Implementations§
Source§impl Options
impl Options
Sourcepub const fn from_radix(radix: u8) -> Options
pub const fn from_radix(radix: u8) -> Options
Create the default options for a given radix.
This sets the exponent to ^
for any radix where e
would be a valid digit.
Sourcepub const fn exponent(&self) -> u8
pub const fn exponent(&self) -> u8
Get the character to designate the exponent component of a float.
Any non-control character is valid, but \t
to \r
are also valid.
The full range is [0x09, 0x0D]
and [0x20, 0x7F]
. Defaults to e
.
§Examples
use lexical_parse_float::options::Options;
assert_eq!(Options::new().exponent(), b'e');
Sourcepub const fn decimal_point(&self) -> u8
pub const fn decimal_point(&self) -> u8
Get the character to separate the integer from the fraction components.
Any non-control character is valid, but \t
to \r
are also valid.
The full range is [0x09, 0x0D]
and [0x20, 0x7F]
. Defaults to .
.
§Examples
use lexical_parse_float::options::Options;
assert_eq!(Options::new().decimal_point(), b'.');
Sourcepub const fn nan_string(&self) -> Option<&'static [u8]>
pub const fn nan_string(&self) -> Option<&'static [u8]>
Get the string representation for NaN
.
The first character must start with N
or n
and all characters must
be valid ASCII letters (A-Z
or a-z
). If set to None
, then parsing
NaN
returns an error. Defaults to NaN
.
§Examples
use lexical_parse_float::options::Options;
assert_eq!(Options::new().nan_string(), Some(b"NaN".as_ref()));
Sourcepub const fn inf_string(&self) -> Option<&'static [u8]>
pub const fn inf_string(&self) -> Option<&'static [u8]>
Get the short string representation for Infinity
.
The first character must start with I
or i
and all characters must
be valid ASCII letters (A-Z
or a-z
). If set to None
, then parsing
Infinity
returns an error. Defaults to inf
.
§Examples
use lexical_parse_float::options::Options;
assert_eq!(Options::new().inf_string(), Some(b"inf".as_ref()));
Sourcepub const fn infinity_string(&self) -> Option<&'static [u8]>
pub const fn infinity_string(&self) -> Option<&'static [u8]>
Get the long string representation for Infinity
.
The first character must start with I
or i
and all characters must
be valid ASCII letters (A-Z
or a-z
). If set to None
, then parsing
Infinity
returns an error. Defaults to infinity
.
§Examples
use lexical_parse_float::options::Options;
assert_eq!(Options::new().infinity_string(), Some(b"infinity".as_ref()));
Sourcepub fn set_lossy(&mut self, lossy: bool)
👎Deprecated: Options should be treated as immutable, use OptionsBuilder
instead. Will be removed in 2.0.
pub fn set_lossy(&mut self, lossy: bool)
OptionsBuilder
instead. Will be removed in 2.0.Set if we disable the use of arbitrary-precision arithmetic.
Sourcepub fn set_exponent(&mut self, exponent: u8)
👎Deprecated: Options should be treated as immutable, use OptionsBuilder
instead. Will be removed in 2.0.
pub fn set_exponent(&mut self, exponent: u8)
OptionsBuilder
instead. Will be removed in 2.0.Set the character to designate the exponent component of a float.
Sourcepub fn set_decimal_point(&mut self, decimal_point: u8)
👎Deprecated: Options should be treated as immutable, use OptionsBuilder
instead. Will be removed in 2.0.
pub fn set_decimal_point(&mut self, decimal_point: u8)
OptionsBuilder
instead. Will be removed in 2.0.Set the character to separate the integer from the fraction components.
Sourcepub fn set_nan_string(&mut self, nan_string: Option<&'static [u8]>)
👎Deprecated: Options should be treated as immutable, use OptionsBuilder
instead. Will be removed in 2.0.
pub fn set_nan_string(&mut self, nan_string: Option<&'static [u8]>)
OptionsBuilder
instead. Will be removed in 2.0.Set the string representation for NaN
.
Sourcepub fn set_inf_string(&mut self, inf_string: Option<&'static [u8]>)
👎Deprecated: Options should be treated as immutable, use OptionsBuilder
instead. Will be removed in 2.0.
pub fn set_inf_string(&mut self, inf_string: Option<&'static [u8]>)
OptionsBuilder
instead. Will be removed in 2.0.Set the short string representation for Infinity
Sourcepub fn set_infinity_string(&mut self, infinity_string: Option<&'static [u8]>)
👎Deprecated: Options should be treated as immutable, use OptionsBuilder
instead. Will be removed in 2.0.
pub fn set_infinity_string(&mut self, infinity_string: Option<&'static [u8]>)
OptionsBuilder
instead. Will be removed in 2.0.Set the long string representation for Infinity
Sourcepub const fn builder() -> OptionsBuilder
pub const fn builder() -> OptionsBuilder
Get OptionsBuilder
as a static function.
Sourcepub const fn rebuild(&self) -> OptionsBuilder
pub const fn rebuild(&self) -> OptionsBuilder
Create OptionsBuilder
using existing values.