Crate lexical[][src]

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.

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.

Conversion API

To String

From String

Configuration Settings

Get Configuration

Set Configuration

Structs

Error

Error type for lexical parsing.

Enums

ErrorCode

Error code, indicating failure type.

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_exponent_default_char

Get default character for the exponent symbol.

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_exponent_default_char

Set the default character for the exponent symbol.

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

A specialized Result type for lexical operations.