pub trait ToLexicalWithOptions: FormattedSize + Number {
type Options: WriteOptions;
// Required method
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§
sourcetype Options: WriteOptions
type Options: WriteOptions
Custom formatting options for writing a number.
Required Methods§
sourcefn to_lexical_with_options<'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] ⓘ
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.