ToLexical

Trait ToLexical 

Source
pub trait ToLexical: FormattedSize + Number {
    // Required method
    fn to_lexical<'a>(self, bytes: &'a mut [u8]) -> &'a mut [u8] ;
}
Available on crate features write-floats or write-integers only.
Expand description

Trait for numerical types that can be serialized to bytes.

To determine the number of bytes required to serialize a value to string, check the associated constants from a required trait:

Required Methods§

Source

fn to_lexical<'a>(self, bytes: &'a mut [u8]) -> &'a mut [u8]

Serializer for a number-to-string conversion.

Returns a subslice of the input buffer containing the written bytes, starting from the same address in memory as the input slice. That is, the bytes provided to the function and the returned buffer reference the same buffer, just with the number of elements truncated to the written digits.

  • value - Number to serialize.
  • bytes - Buffer to write number to.
§Examples
use core::str;

use lexical_core::{format, FormattedSize, ToLexical};

let value: u64 = 1234;
let mut buffer = [0u8; u64::FORMATTED_SIZE_DECIMAL];
let digits = value.to_lexical(&mut buffer);
assert_eq!(str::from_utf8(digits), Ok("1234"));
§Panics

Panics if the buffer is not of sufficient size. The caller must provide a slice of sufficient size. In order to ensure the function will not panic, ensure the buffer has at least FORMATTED_SIZE_DECIMAL elements.

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 ToLexical for f32

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for f64

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for i8

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for i16

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for i32

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for i64

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for i128

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for isize

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for u8

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for u16

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for u32

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for u64

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for u128

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

impl ToLexical for usize

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

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

Implementors§