ParseFloatOptions

Struct ParseFloatOptions 

Source
pub struct ParseFloatOptions { /* private fields */ }
Available on crate feature 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

Source

pub const fn new() -> Options

Create options with default values.

Source

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.

Source

pub const fn is_valid(&self) -> bool

Check if the options state is valid.

Source

pub const fn lossy(&self) -> bool

Get if we disable the use of arbitrary-precision arithmetic.

Lossy algorithms never use the fallback, slow algorithm. Defaults to false.

§Examples
use lexical_parse_float::options::Options;

assert_eq!(Options::new().lossy(), false);
Source

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');
Source

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'.');
Source

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()));
Source

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()));
Source

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()));
Source

pub fn set_lossy(&mut self, lossy: bool)

👎Deprecated: Options should be treated as immutable, use OptionsBuilder instead. Will be removed in 2.0.

Set if we disable the use of arbitrary-precision arithmetic.

Source

pub fn set_exponent(&mut self, exponent: u8)

👎Deprecated: Options should be treated as immutable, use OptionsBuilder instead. Will be removed in 2.0.

Set the character to designate the exponent component of a float.

Source

pub 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.

Set the character to separate the integer from the fraction components.

Source

pub 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.

Set the string representation for NaN.

Source

pub 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.

Set the short string representation for Infinity

Source

pub 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.

Set the long string representation for Infinity

Source

pub const fn builder() -> OptionsBuilder

Get OptionsBuilder as a static function.

Source

pub const fn rebuild(&self) -> OptionsBuilder

Create OptionsBuilder using existing values.

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Options

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Options

Returns the “default value” for a type. Read more
Source§

impl Ord for Options

Source§

fn cmp(&self, other: &Options) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl ParseOptions for Options

Source§

fn is_valid(&self) -> bool

Determine if the options are valid.
Source§

impl PartialEq for Options

Source§

fn eq(&self, other: &Options) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Options

Source§

fn partial_cmp(&self, other: &Options) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Options

Source§

impl StructuralPartialEq for Options

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.