pub struct OptionsBuilder { /* private fields */ }Expand description
Builder for Options.
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()
.decimal_point(b',')
.build_strict();
let value = "1,2345e300";
let result = f64::from_lexical_with_options::<STANDARD>(value.as_bytes(), &OPTIONS);
assert_eq!(result, Ok(1.2345e300));Implementations§
Source§impl OptionsBuilder
impl OptionsBuilder
Sourcepub const fn get_exponent(&self) -> u8
pub const fn get_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::builder().get_exponent(), b'e');Sourcepub const fn get_decimal_point(&self) -> u8
pub const fn get_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::builder().get_decimal_point(), b'.');Sourcepub const fn get_nan_string(&self) -> Option<&'static [u8]>
pub const fn get_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). Defaults to NaN.
§Examples
use lexical_parse_float::Options;
let builder = Options::builder();
assert_eq!(builder.get_nan_string(), Some("NaN".as_bytes()));Sourcepub const fn get_inf_string(&self) -> Option<&'static [u8]>
pub const fn get_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). Defaults to inf.
§Examples
use lexical_parse_float::Options;
let builder = Options::builder();
assert_eq!(builder.get_inf_string(), Some("inf".as_bytes()));Sourcepub const fn get_infinity_string(&self) -> Option<&'static [u8]>
pub const fn get_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). Defaults to infinity.
§Examples
use lexical_parse_float::Options;
let builder = Options::builder();
assert_eq!(builder.get_infinity_string(), Some("infinity".as_bytes()));Sourcepub const fn exponent(self, exponent: u8) -> Self
pub const fn exponent(self, exponent: u8) -> Self
Set 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;
const OPTIONS: Options = Options::builder()
.exponent(b'^')
.build_strict();
assert_eq!(OPTIONS.exponent(), b'^');Sourcepub const fn decimal_point(self, decimal_point: u8) -> Self
pub const fn decimal_point(self, decimal_point: u8) -> Self
Set 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;
const OPTIONS: Options = Options::builder()
.exponent(b',')
.build_strict();
assert_eq!(OPTIONS.exponent(), b',');Sourcepub const fn nan_string(self, nan_string: Option<&'static [u8]>) -> Self
pub const fn nan_string(self, nan_string: Option<&'static [u8]>) -> Self
Set 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;
const OPTIONS: Options = Options::builder()
.nan_string(Some(b"nan"))
.build_strict();
assert_eq!(OPTIONS.nan_string(), Some(b"nan".as_ref()));Panics
Setting a value with more than 50 elements will panic at runtime. You
should always build the format using build_strict or checking
is_valid prior to using the format, to avoid unexpected panics.
Sourcepub const fn inf_string(self, inf_string: Option<&'static [u8]>) -> Self
pub const fn inf_string(self, inf_string: Option<&'static [u8]>) -> Self
Set 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;
const OPTIONS: Options = Options::builder()
.inf_string(Some(b"Infinity"))
.build_strict();
assert_eq!(OPTIONS.inf_string(), Some(b"Infinity".as_ref()));Panics
Setting a value with more than 50 elements or one that is longer than
infinity_string will panic at runtime. You should always build
the format using build_strict or checking is_valid prior to
using the format, to avoid unexpected panics.
Sourcepub const fn infinity_string(
self,
infinity_string: Option<&'static [u8]>,
) -> Self
pub const fn infinity_string( self, infinity_string: Option<&'static [u8]>, ) -> Self
Set 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;
const OPTIONS: Options = Options::builder()
.infinity_string(Some(b"Infinity"))
.build_strict();
assert_eq!(OPTIONS.infinity_string(), Some(b"Infinity".as_ref()));Panics
Setting a value with more than 50 elements or one that is shorter than
inf_string will panic at runtime. You should always build the format
using build_strict or checking is_valid prior to
using the format, to avoid unexpected panics.
Sourcepub const fn build_unchecked(&self) -> Options
pub const fn build_unchecked(&self) -> Options
Build the Options struct without validation.
§Panics
This is completely safe, however, misusing this, especially
the nan_string, inf_string, and infinity_string could
panic at runtime. Always use is_valid prior to using the built
options.
Sourcepub const fn build_strict(&self) -> Options
pub const fn build_strict(&self) -> Options
Trait Implementations§
Source§impl Clone for OptionsBuilder
impl Clone for OptionsBuilder
Source§fn clone(&self) -> OptionsBuilder
fn clone(&self) -> OptionsBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more