OptionsBuilder

Struct OptionsBuilder 

Source
pub struct OptionsBuilder { /* private fields */ }
Available on crate feature parse-floats only.
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

Source

pub const fn new() -> OptionsBuilder

Create new options builder with default options.

Source

pub const fn get_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::builder().get_lossy(), false);
Source

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

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

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

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

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

pub const fn lossy(self, lossy: bool) -> OptionsBuilder

Set 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;

const OPTIONS: Options = Options::builder()
    .lossy(true)
    .build_strict();
assert_eq!(OPTIONS.lossy(), true);
Source

pub const fn exponent(self, exponent: u8) -> OptionsBuilder

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

pub const fn decimal_point(self, decimal_point: u8) -> OptionsBuilder

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

pub const fn nan_string( self, nan_string: Option<&'static [u8]>, ) -> OptionsBuilder

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.

Source

pub const fn inf_string( self, inf_string: Option<&'static [u8]>, ) -> OptionsBuilder

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.

Source

pub const fn infinity_string( self, infinity_string: Option<&'static [u8]>, ) -> OptionsBuilder

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.

Source

pub const fn is_valid(&self) -> bool

Check if the builder state is valid.

Source

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.

Source

pub const fn build_strict(&self) -> Options

Build the Options struct, panicking if the builder is invalid.

§Panics

If the built options are not valid. This should always be used within a const context to avoid panics at runtime.

Source

pub const fn build(&self) -> Result<Options, Error>

Build the Options struct.

§Errors

If the NaN, Inf, or Infinity strings are too long or invalid digits/characters are provided for some numerical formats.

Trait Implementations§

Source§

impl Clone for OptionsBuilder

Source§

fn clone(&self) -> OptionsBuilder

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 OptionsBuilder

Source§

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

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

impl Default for OptionsBuilder

Source§

fn default() -> OptionsBuilder

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

impl Ord for OptionsBuilder

Source§

fn cmp(&self, other: &OptionsBuilder) -> 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 PartialEq for OptionsBuilder

Source§

fn eq(&self, other: &OptionsBuilder) -> 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 OptionsBuilder

Source§

fn partial_cmp(&self, other: &OptionsBuilder) -> 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 OptionsBuilder

Source§

impl StructuralPartialEq for OptionsBuilder

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.