[][src]Crate lexical

Fast lexical conversion routines.

Fast lexical conversion routines for both std and no_std environments. Lexical provides routines to convert numbers to and from decimal strings. Lexical also supports non-base 10 numbers, with the radix feature, for both integers and floats. Lexical is simple to use, and exports up to 10 functions in the high-level API.

Lexical makes heavy use of unsafe code for performance, and therefore may introduce memory-safety issues. Although the code is tested with wide variety of inputs to minimize the risk of memory-safety bugs, no guarantees are made and you should use it at your own risk.

Getting Started

extern crate lexical;

// Number to string
lexical::to_string(3.0);            // "3.0", always has a fraction suffix,
lexical::to_string(3);              // "3"

// String to number.
let i: i32 = lexical::parse("3");            // 3, auto-type deduction.
let f: f32 = lexical::parse("3.5");          // 3.5
let d = lexical::parse::<f64, _>("3.5");     // 3.5, explicit type hints.
let d = lexical::try_parse::<f64, _>("3.5"); // Ok(3.5), error checking parse.
let d = lexical::try_parse::<f64, _>("3a");  // Err(Error(_)), failed to parse.

Structs

Error

Custom error for numeric parsing.

Enums

ErrorKind

Type of error encountered during numeric parsing.

RoundingKind

Rounding type for float-parsing.

Statics

EXPONENT_DEFAULT_CHAR

Default character for scientific notation, used when the radix < 15.

FLOAT_ROUNDING

The rounding scheme for float conversions.

INFINITY_STRING

Long infinity literal

INF_STRING

Short infinity literal

NAN_STRING

Not a Number literal

Traits

FromBytes

Trait for numerical types that can be parsed from bytes.

FromBytesLossy

Trait for floating-point types that can be parsed using lossy algorithms from bytes.

ToBytes

Trait for numerical types that can be serialized to bytes.

Functions

parse

High-level conversion of decimal-encoded bytes to a number.

parse_lossy

High-level lossy conversion of decimal-encoded bytes to a number.

to_string

High-level conversion of a number to a decimal-encoded string.

try_parse

High-level conversion of decimal-encoded bytes to a number.

try_parse_lossy

High-level lossy conversion of decimal-encoded bytes to a number.