#[repr(C)]pub struct FixedCapacityBytesU16<const CAPACITY: usize> { /* private fields */ }
Expand description
Container for storing a number of bytes limited by the specified fixed capacity as u16
.
See also FixedCapacityBytesU8
if you need to store fewer bytes.
In contrast to VariableBytes
, which can store arbitrary amount of data and can change the
capacity, this container has fixed predefined capacity and occupies it regardless of how many
bytes are actually stored inside. This might seem limiting but allows implementing
TrivialType
trait, enabling its use for fields in data structures that derive
TrivialType
themselves, which isn’t the case with VariableBytes
.
Implementations§
Source§impl<const CAPACITY: usize> FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> FixedCapacityBytesU16<CAPACITY>
Sourcepub fn try_from_bytes(bytes: &[u8]) -> Option<Self>
pub fn try_from_bytes(bytes: &[u8]) -> Option<Self>
Try to create an instance from provided bytes.
Returns None
if provided bytes do not fit into the capacity.
Sourcepub fn get_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn get_bytes_mut(&mut self) -> &mut [u8] ⓘ
Exclusive access to stored bytes
Sourcepub fn append(&mut self, bytes: &[u8]) -> bool
pub fn append(&mut self, bytes: &[u8]) -> bool
Append some bytes.
true
is returned on success, but if there isn’t enough capacity left, false
is.
Sourcepub fn truncate(&mut self, new_len: u16) -> bool
pub fn truncate(&mut self, new_len: u16) -> bool
Truncate stored bytes to this length.
Returns true
on success or false
if new_len
is larger than Self::len()
.
Trait Implementations§
Source§impl<const CAPACITY: usize> Clone for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> Clone for FixedCapacityBytesU16<CAPACITY>
Source§fn clone(&self) -> FixedCapacityBytesU16<CAPACITY>
fn clone(&self) -> FixedCapacityBytesU16<CAPACITY>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<const CAPACITY: usize> Debug for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> Debug for FixedCapacityBytesU16<CAPACITY>
Source§impl<const CAPACITY: usize> Default for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> Default for FixedCapacityBytesU16<CAPACITY>
Source§impl<const CAPACITY: usize> TrivialType for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> TrivialType for FixedCapacityBytesU16<CAPACITY>
Source§const METADATA: &[u8]
const METADATA: &[u8]
IoTypeMetadataKind
for encoding details.const SIZE: u32 = _
Source§unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>
unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>
impl<const CAPACITY: usize> Copy for FixedCapacityBytesU16<CAPACITY>
Auto Trait Implementations§
impl<const CAPACITY: usize> Freeze for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> RefUnwindSafe for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> Send for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> Sync for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> Unpin for FixedCapacityBytesU16<CAPACITY>
impl<const CAPACITY: usize> UnwindSafe for FixedCapacityBytesU16<CAPACITY>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IoType for Twhere
T: TrivialType,
impl<T> IoType for Twhere
T: TrivialType,
Source§const METADATA: &'static [u8] = const METADATA: &'_ [u8] = T::METADATA;
const METADATA: &'static [u8] = const METADATA: &'_ [u8] = T::METADATA;
IoTypeMetadataKind
for encoding detailsSource§type PointerType = T
type PointerType = T
IoType
represents