lexical_core

Trait ToLexicalWithOptions

Source
pub trait ToLexicalWithOptions: FormattedSize + Number {
    type Options: WriteOptions;

    // Required methods
    unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>(
        self,
        bytes: &'a mut [u8],
        options: &Self::Options,
    ) -> &'a mut [u8];
    fn to_lexical_with_options<'a, const FORMAT: u128>(
        self,
        bytes: &'a mut [u8],
        options: &Self::Options,
    ) -> &'a mut [u8];
}
Expand description

Trait for numerical types that can be serialized to bytes with custom options.

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

The Options type specifies the configurable options to provide.

Required Associated Types§

Source

type Options: WriteOptions

Custom formatting options for writing a number.

Required Methods§

Source

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'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.

  • FORMAT - Flags and characters designating the number grammar.
  • value - Number to serialize.
  • bytes - Buffer to write number to.
  • options - Options for number formatting.
§Safety

Safe as long as the caller has provided a buffer of at least FORMATTED_SIZE elements. If a smaller buffer is provided, a buffer overflow is very likely. If you are changing the number significant digits written, the exponent break points, or disabling scientific notation, you will need a larger buffer than the one provided. An upper limit on the buffer size can then be determined using WriteOptions::buffer_size. If you are not using min_significant_digits, 1200 bytes is always enough to hold the the output for a custom radix, and 400 is always enough for decimal strings.

§Panics

Floats Only

These panics are only when using uncommon features for float writing, represent configuration errors, so runtime error handling is not provided.

Panics if the provided number format is invalid, or if the mantissa radix is not equal to the exponent base and the mantissa radix/exponent base combinations are not in the following list:

  • 4, 2
  • 8, 2
  • 16, 2
  • 32, 2
  • 16, 4

Panics as well if the NaN or Inf string provided to the writer is disabled, but the value provided is NaN or Inf, respectively.

Source

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'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.

  • FORMAT - Flags and characters designating the number grammar.
  • value - Number to serialize.
  • bytes - Buffer to write number to.
  • options - Options for number formatting.
§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 elements. If you are changing the number significant digits written, the exponent break points, or disabling scientific notation, you will need a larger buffer than the one provided. An upper limit on the buffer size can then be determined using WriteOptions::buffer_size. If you are not using min_significant_digits, 1200 bytes is always enough to hold the the output for a custom radix, and 400 is always enough for decimal strings.

Floats Only

These panics are only when using uncommon features for float writing, represent configuration errors, so runtime error handling is not provided.

Also panics if the provided number format is invalid, or if the mantissa radix is not equal to the exponent base and the mantissa radix/exponent base combinations are not in the following list:

  • 4, 2
  • 8, 2
  • 16, 2
  • 32, 2
  • 16, 4

Panics as well if the NaN or Inf string provided to the writer is disabled, but the value provided is NaN or Inf, respectively.

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

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for f64

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for i8

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for i16

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for i32

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for i64

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for i128

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for isize

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for u8

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for u16

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for u32

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for u64

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for u128

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

impl ToLexicalWithOptions for usize

Source§

type Options = Options

Source§

unsafe fn to_lexical_with_options_unchecked<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &Self::Options, ) -> &'a mut [u8]

Implementors§