[][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").unwrap();      // 3, auto-type deduction.
let f: f32 = lexical::parse("3.5").unwrap();    // 3.5
let d = lexical::parse::<f64, _>("3.5");        // Ok(3.5), successful parse.
let d = lexical::parse::<f64, _>("3a");         // Err(Error(_)), failed to parse.

Structs

Error

C-compatible error for FFI.

Enums

ErrorCode

Error code, indicating failure type.

Statics

EXPONENT_DEFAULT_CHAR

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

Traits

FromLexical

Trait for numerical types that can be parsed from bytes.

FromLexicalLossy

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

ToLexical

Trait for numerical types that can be serialized to bytes.

Functions

get_inf_string

Get the short representation of an Infinity literal as a byte slice.

get_infinity_string

Get the long representation of an Infinity literal as a byte slice.

get_nan_string

Get string representation of Not a Number as a byte slice.

parse

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

parse_lossy

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

parse_partial

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

parse_partial_lossy

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

set_inf_string

Set the short representation of Infinity from a byte slice.

set_infinity_string

Set the long representation of Infinity from a byte slice.

set_nan_string

Set representation of Not a Number from a byte slice.

to_string

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

Type Definitions

Result

Rust intrinsic result type from parsing strings-to-numbers for FFI.