pub struct FixedBytes<const N: usize> { /* private fields */ }Expand description
Stack-allocated arbitrary bytes with a fixed maximum capacity.
Implementations§
Source§impl<const N: usize> FixedBytes<N>
impl<const N: usize> FixedBytes<N>
Sourcepub const fn with_size(size: usize) -> Self
pub const fn with_size(size: usize) -> Self
Creates a zero-filled buffer with an initialized length.
§Panics
Panics when size exceeds the capacity.
Sourcepub const fn remaining_capacity(&self) -> usize
pub const fn remaining_capacity(&self) -> usize
Returns the number of bytes that can still be appended.
Sourcepub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Returns the initialized portion of the buffer mutably.
Sourcepub fn try_as_str(&self) -> Result<&str, Utf8Error>
pub fn try_as_str(&self) -> Result<&str, Utf8Error>
Interprets the initialized bytes as UTF-8.
Sourcepub fn allocate(&mut self, bytes: usize)
pub fn allocate(&mut self, bytes: usize)
Extends the initialized portion with zero-filled bytes.
§Panics
Panics if the requested bytes exceed the remaining capacity.
Sourcepub fn try_from_slice(value: &[u8]) -> Result<Self, CapacityError>
pub fn try_from_slice(value: &[u8]) -> Result<Self, CapacityError>
Copies a byte slice into a new buffer.
Sourcepub fn try_push_slice(
&mut self,
value: &[u8],
) -> Result<Range<usize>, CapacityError>
pub fn try_push_slice( &mut self, value: &[u8], ) -> Result<Range<usize>, CapacityError>
Appends a slice and returns the occupied range.
Sourcepub fn push_slice(&mut self, value: &[u8]) -> Range<usize> ⓘ
pub fn push_slice(&mut self, value: &[u8]) -> Range<usize> ⓘ
Appends a slice and returns the occupied range.
§Panics
Panics if the slice exceeds the remaining capacity.
Sourcepub fn try_push_byte(&mut self, value: u8) -> Result<usize, CapacityError>
pub fn try_push_byte(&mut self, value: u8) -> Result<usize, CapacityError>
Appends one byte and returns its index.
Trait Implementations§
Source§impl<const N: usize> Clone for FixedBytes<N>
impl<const N: usize> Clone for FixedBytes<N>
Source§fn clone(&self) -> FixedBytes<N>
fn clone(&self) -> FixedBytes<N>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<const N: usize> Copy for FixedBytes<N>
Source§impl<const N: usize> Debug for FixedBytes<N>
impl<const N: usize> Debug for FixedBytes<N>
Source§impl<const N: usize> Default for FixedBytes<N>
impl<const N: usize> Default for FixedBytes<N>
Source§impl<const N: usize> Display for FixedBytes<N>
impl<const N: usize> Display for FixedBytes<N>
impl<const N: usize> Eq for FixedBytes<N>
Source§impl<const N: usize> PartialEq for FixedBytes<N>
impl<const N: usize> PartialEq for FixedBytes<N>
impl<const N: usize> StructuralPartialEq for FixedBytes<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for FixedBytes<N>
impl<const N: usize> RefUnwindSafe for FixedBytes<N>
impl<const N: usize> Send for FixedBytes<N>
impl<const N: usize> Sync for FixedBytes<N>
impl<const N: usize> Unpin for FixedBytes<N>
impl<const N: usize> UnsafeUnpin for FixedBytes<N>
impl<const N: usize> UnwindSafe for FixedBytes<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more