Skip to main content

FixedBytes

Struct FixedBytes 

Source
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>

Source

pub const fn new() -> Self

Creates an empty buffer.

Source

pub const fn empty() -> Self

Compatibility name for new.

Source

pub const fn with_size(size: usize) -> Self

Creates a zero-filled buffer with an initialized length.

§Panics

Panics when size exceeds the capacity.

Source

pub const fn len(&self) -> usize

Returns the number of initialized bytes.

Source

pub const fn is_empty(&self) -> bool

Returns whether the buffer contains no initialized bytes.

Source

pub const fn capacity(&self) -> usize

Returns the maximum number of bytes the buffer can hold.

Source

pub const fn remaining_capacity(&self) -> usize

Returns the number of bytes that can still be appended.

Source

pub fn as_bytes(&self) -> &[u8]

Returns the initialized portion of the buffer.

Source

pub fn as_bytes_mut(&mut self) -> &mut [u8]

Returns the initialized portion of the buffer mutably.

Source

pub fn try_as_str(&self) -> Result<&str, Utf8Error>

Interprets the initialized bytes as UTF-8.

Source

pub fn as_str(&self) -> &str

Returns the initialized bytes as UTF-8.

§Panics

Panics if the buffer does not contain valid UTF-8.

Source

pub fn clear(&mut self)

Removes all initialized bytes.

Source

pub fn truncate(&mut self, new_len: usize)

Shortens the initialized portion to new_len.

§Panics

Panics if new_len exceeds the current length.

Source

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.

Source

pub fn try_from_slice(value: &[u8]) -> Result<Self, CapacityError>

Copies a byte slice into a new buffer.

Source

pub fn try_push_slice( &mut self, value: &[u8], ) -> Result<Range<usize>, CapacityError>

Appends a slice and returns the occupied range.

Source

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.

Source

pub fn try_push_byte(&mut self, value: u8) -> Result<usize, CapacityError>

Appends one byte and returns its index.

Source

pub fn push_byte(&mut self, value: u8) -> usize

Appends one byte and returns its index.

§Panics

Panics if the buffer is full.

Trait Implementations§

Source§

impl<const N: usize> Clone for FixedBytes<N>

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Copy for FixedBytes<N>

Source§

impl<const N: usize> Debug for FixedBytes<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for FixedBytes<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize> Display for FixedBytes<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Eq for FixedBytes<N>

Source§

impl<const N: usize> From<&[u8; N]> for FixedBytes<N>

Source§

fn from(value: &[u8; N]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<&[u8]> for FixedBytes<N>

Source§

fn from(value: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> PartialEq for FixedBytes<N>

Source§

fn eq(&self, other: &FixedBytes<N>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<const N: usize> StructuralPartialEq for FixedBytes<N>

Source§

impl<const N: usize> TryFrom<FixedBytes<N>> for FixedStr<N>

Source§

type Error = Utf8Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: FixedBytes<N>) -> Result<Self, Self::Error>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.