pub struct Buffer<const N: usize> { /* private fields */ }Expand description
A correctly sized stack allocation for the formatted bytes to be written into.
Examples
let mut buffer = const_hex::Buffer::new();
let printed = buffer.format(b"1234");
assert_eq!(printed, "31323334");Implementations§
source§impl<const N: usize> Buffer<N>
impl<const N: usize> Buffer<N>
sourcepub const fn new() -> Self
pub const fn new() -> Self
This is a cheap operation; you don’t need to worry about reusing buffers for efficiency.
sourcepub const fn const_format(self, array: &[u8; N]) -> Self
pub const fn const_format(self, array: &[u8; N]) -> Self
Print an array of bytes into this buffer.
sourcepub const fn const_format_upper(self, array: &[u8; N]) -> Self
pub const fn const_format_upper(self, array: &[u8; N]) -> Self
Print an array of bytes into this buffer.
sourcepub fn format(&mut self, array: &[u8; N]) -> &mut str
pub fn format(&mut self, array: &[u8; N]) -> &mut str
Print an array of bytes into this buffer and return a reference to its lower hex string representation within the buffer.
sourcepub fn format_upper(&mut self, array: &[u8; N]) -> &mut str
pub fn format_upper(&mut self, array: &[u8; N]) -> &mut str
Print an array of bytes into this buffer and return a reference to its upper hex string representation within the buffer.
sourcepub fn format_slice<T: AsRef<[u8]>>(&mut self, slice: T) -> &mut str
pub fn format_slice<T: AsRef<[u8]>>(&mut self, slice: T) -> &mut str
Print a slice of bytes into this buffer and return a reference to its lower hex string representation within the buffer.
Panics
If the slice is not exactly N bytes long.
sourcepub fn format_slice_upper<T: AsRef<[u8]>>(&mut self, slice: T) -> &mut str
pub fn format_slice_upper<T: AsRef<[u8]>>(&mut self, slice: T) -> &mut str
Print a slice of bytes into this buffer and return a reference to its upper hex string representation within the buffer.
Panics
If the slice is not exactly N bytes long.
sourcepub const fn as_str(&self) -> &str
pub const fn as_str(&self) -> &str
Returns a reference to the underlying bytes casted to a string slice.
Note that this contains only null (‘\0’) bytes before any formatting is done.
sourcepub fn as_mut_str(&mut self) -> &mut str
pub fn as_mut_str(&mut self) -> &mut str
Returns a reference to the underlying bytes casted to a string slice.
Note that this contains only null (‘\0’) bytes before any formatting is done.