FromLexical

Trait FromLexical 

Source
pub trait FromLexical: Number {
    // Required methods
    fn from_lexical(bytes: &[u8]) -> Result<Self>;
    fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>;
}
Available on crate features parse-floats or parse-integers only.
Expand description

Trait for numerical types that can be parsed from bytes.

Required Methods§

Source

fn from_lexical(bytes: &[u8]) -> Result<Self>

Checked parser for a string-to-number conversion.

This method parses the entire string, returning an error if any invalid digits are found during parsing. Returns a Result containing either the parsed value, or an error containing any errors that occurred during parsing.

  • bytes - Slice containing a numeric string.
§Examples
use lexical_core::FromLexical;

let value = "1234";
let parsed = u64::from_lexical(value.as_bytes());
assert_eq!(parsed, Ok(1234));
Source

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Checked parser for a string-to-number conversion.

This method parses until an invalid digit is found (or the end of the string), returning the number of processed digits and the parsed value until that point. Returns a Result containing either the parsed value and the number of processed digits, or an error containing any errors that occurred during parsing.

  • bytes - Slice containing a numeric string.
§Examples
use lexical_core::FromLexical;

let value = "1234";
let parsed = u64::from_lexical_partial(value.as_bytes());
assert_eq!(parsed, Ok((1234, 4)));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromLexical for f32

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for f64

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for i8

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for i16

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for i32

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for i64

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for i128

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for isize

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for u8

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for u16

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for u32

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for u64

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for u128

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.
Source§

impl FromLexical for usize

Source§

fn from_lexical(bytes: &[u8]) -> Result<Self>

Available on crate features parse-floats or parse-integers only.
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(Self, usize)>

Available on crate features parse-floats or parse-integers only.

Implementors§