logos.lang.num.parse

Module lang · package logos-lang

Traits

traitFromStr

trait FromStr

Parses a value of Self from a str; Rust’s core::str::FromStr with the error type as trait type-param E (Logos traits carry no associated types outside the Fn-family). Backs the s.parse::<T>() idiom.

Implemented by: i32 i64 u32 u64 f32 f64

Functions

fnf32_from_str

fn f32_from_str(s: &[u8]) -> Result

Parses s as an f32 by parsing as f64 and narrowing (see f64_from_str). Double rounding may differ from a direct f32 parse by an ulp.

fnf64_from_str

fn f64_from_str(s: &[u8]) -> Result

Parses s as an f64, mirroring f64::from_str; the whole input must match. Accepts optional +/-, decimal mantissa with optional fraction, optional e/E exponent, and case-insensitive inf/infinity/nan. Not correctly rounded: accurate to a few ulp (unlike Rust’s exact dec2flt).

fni32_from_str

fn i32_from_str(s: &[u8]) -> Result

Parses s as a base-10 i32; s.parse::<i32>() lowers here.

fni32_from_str_radix

fn i32_from_str_radix(s: &[u8], radix: u32) -> Result

Parses s as an i32 in the given radix, mirroring i32::from_str_radix. Accepts a leading +/-; errors: Empty, InvalidDigit, PosOverflow/NegOverflow. radix is unvalidated (no panic outside 2..=36, unlike Rust); digit set 0-9, a-z/A-Z.

fni64_from_str

fn i64_from_str(s: &[u8]) -> Result

Parses s as a base-10 i64; s.parse::<i64>() lowers here.

fni64_from_str_radix

fn i64_from_str_radix(s: &[u8], radix: u32) -> Result

Parses s as an i64 in the given radix, mirroring i64::from_str_radix. Accepts a leading +/-; errors: Empty, InvalidDigit, PosOverflow/NegOverflow. radix is not validated (no panic outside 2..=36, unlike Rust). Trap: i64::MIN itself is rejected as NegOverflow (magnitude is capped at i64::MAX).

fnu32_from_str

fn u32_from_str(s: &[u8]) -> Result

Parses s as a base-10 u32; s.parse::<u32>() lowers here.

fnu32_from_str_radix

fn u32_from_str_radix(s: &[u8], radix: u32) -> Result

Parses s as a u32 in the given radix, mirroring u32::from_str_radix. Accepts a leading +; a leading - is InvalidDigit. Errors: Empty, InvalidDigit, PosOverflow. radix is not validated (no panic outside 2..=36).

fnu64_from_str

fn u64_from_str(s: &[u8]) -> Result

Parses s as a base-10 u64; s.parse::<u64>() lowers here.

fnu64_from_str_radix

fn u64_from_str_radix(s: &[u8], radix: u32) -> Result

Parses s as a u64 in the given radix, mirroring u64::from_str_radix. Accepts a leading +; a leading - is InvalidDigit. Errors: Empty, InvalidDigit, PosOverflow. radix is not validated (no panic outside 2..=36).