pub struct FixedCapacityString<const CAPACITY: usize> { /* private fields */ }Expand description
Container for storing a UTF-8 string limited by the specified fixed bytes capacity.
This is a string only by convention, there is no runtime verification done, contents is treated as regular bytes.
This is just a wrapper for FixedCapacityElements of bytes that the type dereferences to
with a different semantic meaning.
CAPACITY must not exceed u32::MAX - 4.
Implementations§
Source§impl<const CAPACITY: usize> FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> FixedCapacityString<CAPACITY>
Sourcepub fn try_from_str(s: &str) -> Option<Self>
pub fn try_from_str(s: &str) -> Option<Self>
Try to create an instance from provided string.
Returns None if provided string does not fit into the capacity.
Sourcepub fn try_from_slice(bytes: &[u8]) -> Option<Self>
pub fn try_from_slice(bytes: &[u8]) -> Option<Self>
Try to create an instance from provided bytes.
Returns None if provided bytes do not fit into the capacity.
Methods from Deref<Target = FixedCapacityElements<u8, CAPACITY>>§
Sourcepub fn get_elements(&self) -> &[Element]
pub fn get_elements(&self) -> &[Element]
Access to stored elements.
Returns no elements if the number of elements exceeds CAPACITY, which is only possible for
an instance created from invalid bytes.
Sourcepub fn get_elements_mut(&mut self) -> &mut [Element]
pub fn get_elements_mut(&mut self) -> &mut [Element]
Exclusive access to stored elements.
Returns no elements if the number of elements exceeds CAPACITY, which is only possible for
an instance created from invalid bytes.
Sourcepub fn len(&self) -> u32
pub fn len(&self) -> u32
Number of stored elements.
May exceed CAPACITY for an instance created from invalid bytes.
Sourcepub fn append(&mut self, elements: &[Element]) -> bool
pub fn append(&mut self, elements: &[Element]) -> bool
Append some elements.
true is returned on success, but if there isn’t enough capacity left, false is.
Sourcepub fn truncate(&mut self, new_len: u32) -> bool
pub fn truncate(&mut self, new_len: u32) -> bool
Truncate stored elements 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 FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> Clone for FixedCapacityString<CAPACITY>
Source§fn clone(&self) -> FixedCapacityString<CAPACITY>
fn clone(&self) -> FixedCapacityString<CAPACITY>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<const CAPACITY: usize> Copy for FixedCapacityString<CAPACITY>
Source§impl<const CAPACITY: usize> Debug for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> Debug for FixedCapacityString<CAPACITY>
Source§impl<const CAPACITY: usize> Default for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> Default for FixedCapacityString<CAPACITY>
Source§impl<const CAPACITY: usize> Deref for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> Deref for FixedCapacityString<CAPACITY>
Source§impl<const CAPACITY: usize> DerefMut for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> DerefMut for FixedCapacityString<CAPACITY>
Source§impl<const CAPACITY: usize> TrivialType for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> TrivialType for FixedCapacityString<CAPACITY>
Source§const ALIGNMENT: Alignment = FixedCapacityElements<u8, CAPACITY>::ALIGNMENT
const ALIGNMENT: Alignment = FixedCapacityElements<u8, CAPACITY>::ALIGNMENT
Source§const METADATA: &[u8]
const METADATA: &[u8]
IoTypeMetadataKind for encoding details.Source§fn try_from_bytes_unaligned(bytes: &[u8]) -> Option<(&Unaligned<Self>, &[u8])>
fn try_from_bytes_unaligned(bytes: &[u8]) -> Option<(&Unaligned<Self>, &[u8])>
bytes, which don’t need to be aligned. Read moreconst SIZE: u32 = _
Source§final fn try_from_bytes(bytes: &[u8]) -> Option<(&Self, &[u8])>
final fn try_from_bytes(bytes: &[u8]) -> Option<(&Self, &[u8])>
bytes, returns the value and the remaining bytes. Read moreSource§final fn try_from_bytes_exact(bytes: &[u8]) -> Option<&Self>
final fn try_from_bytes_exact(bytes: &[u8]) -> Option<&Self>
Self::try_from_bytes(), but returns None if there are more bytes than the valueSource§final fn try_from_bytes_mut(bytes: &mut [u8]) -> Option<(&mut Self, &mut [u8])>
final fn try_from_bytes_mut(bytes: &mut [u8]) -> Option<(&mut Self, &mut [u8])>
Self::try_from_bytes(), but returns an exclusive reference. Read moreSource§final fn try_read_unaligned(bytes: &[u8]) -> Option<(Self, &[u8])>
final fn try_read_unaligned(bytes: &[u8]) -> Option<(Self, &[u8])>
bytes, which don’t need to be aligned, returns the value
and the remaining bytesSource§final fn try_read_unaligned_exact(bytes: &[u8]) -> Option<Self>
final fn try_read_unaligned_exact(bytes: &[u8]) -> Option<Self>
Self::try_read_unaligned(), but returns None if there are more bytes than the
valueSource§final unsafe fn read_unaligned(bytes: &[u8]) -> Option<Self>
final unsafe fn read_unaligned(bytes: &[u8]) -> Option<Self>
Source§final unsafe fn read_unaligned_unchecked(bytes: &[u8]) -> Self
final unsafe fn read_unaligned_unchecked(bytes: &[u8]) -> Self
Self::read_unaligned(), but doesn’t do any checks at all. Read moreSource§final unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>
final unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>
Source§final unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self
final unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self
Self::from_bytes(), but doesn’t do any checks at all. Read moreSource§final unsafe fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self>
final unsafe fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self>
Source§final unsafe fn from_bytes_mut_unchecked(bytes: &mut [u8]) -> &mut Self
final unsafe fn from_bytes_mut_unchecked(bytes: &mut [u8]) -> &mut Self
Self::from_bytes_mut(), but doesn’t do any checks at all. Read moreAuto Trait Implementations§
impl<const CAPACITY: usize> Freeze for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> RefUnwindSafe for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> Send for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> Sync for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> Unpin for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> UnsafeUnpin for FixedCapacityString<CAPACITY>
impl<const CAPACITY: usize> UnwindSafe for FixedCapacityString<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 representsSource§unsafe fn from_ptr<'a>(
ptr: &'a NonNull<<T as IoType>::PointerType>,
size: &'a u32,
capacity: u32,
) -> impl Deref<Target = T> + 'a
unsafe fn from_ptr<'a>( ptr: &'a NonNull<<T as IoType>::PointerType>, size: &'a u32, capacity: u32, ) -> impl Deref<Target = T> + 'a
Source§unsafe fn from_mut_ptr<'a>(
ptr: &'a mut NonNull<<T as IoType>::PointerType>,
_size: &'a mut u32,
capacity: u32,
) -> impl DerefMut + 'a
unsafe fn from_mut_ptr<'a>( ptr: &'a mut NonNull<<T as IoType>::PointerType>, _size: &'a mut u32, capacity: u32, ) -> impl DerefMut + 'a
Source§unsafe fn try_from_ptr<'a>(
ptr: &'a NonNull<<T as IoType>::PointerType>,
size: &'a u32,
capacity: u32,
) -> Option<impl Deref<Target = T> + 'a>
unsafe fn try_from_ptr<'a>( ptr: &'a NonNull<<T as IoType>::PointerType>, size: &'a u32, capacity: u32, ) -> Option<impl Deref<Target = T> + 'a>
Source§unsafe fn try_from_mut_ptr<'a>(
ptr: &'a mut NonNull<<T as IoType>::PointerType>,
size: &'a mut u32,
capacity: u32,
) -> Option<impl DerefMut + 'a>
unsafe fn try_from_mut_ptr<'a>( ptr: &'a mut NonNull<<T as IoType>::PointerType>, size: &'a mut u32, capacity: u32, ) -> Option<impl DerefMut + 'a>
Self::try_from_ptr(), but returns an exclusive reference. Read more