pub unsafe fn write_unchecked<N: ToLexical>(n: N, bytes: &mut [u8]) -> &mut [u8]Notable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Expand description

Write number to string, without bounds checking the buffer.

Returns a subslice of the input buffer containing the written bytes, starting from the same address in memory as the input slice.

  • value - Number to serialize.
  • bytes - Buffer to write number to.

Safety

If the buffer is not be large enough to hold the serialized number, it will overflow the buffer unless the safe feature is enabled. Buffer overflows are severe security vulnerabilities, and therefore to ensure the function will not overwrite the buffer, provide a buffer with at least {integer}::FORMATTED_SIZE elements.

Example

#[cfg(feature = "write-floats")] {
// import `BUFFER_SIZE` to get the maximum bytes written by the number.
use lexical_core::BUFFER_SIZE;

let mut buffer = [0u8; BUFFER_SIZE];
let float = 3.14159265359_f32;

unsafe {
    lexical_core::write_unchecked(float, &mut buffer);
}

assert_eq!(&buffer[0..9], b"3.1415927");