pub struct LiteStr<const N: usize> { /* private fields */ }Expand description
Fixed-capacity, stack-only UTF-8 string stored in a single [u8; N] array.
The string is stored as raw bytes with C-style nul termination.
Its logical length is determined at runtime by the position of the first nul byte (b'\0').
All bytes after the string content are guaranteed to be zero.
The type guarantees that the prefix up to the first nul is always valid UTF-8 (when constructed through the safe API).
Implementations§
Source§impl<const N: usize> LiteStr<N>
impl<const N: usize> LiteStr<N>
pub const SIZE: usize = N
Sourcepub fn from_str(s: &str) -> Self
pub fn from_str(s: &str) -> Self
Recommended ergonomic constructor – truncates at a UTF-8 boundary if necessary.
Sourcepub fn as_str(&self) -> Result<&str, LiteStrErr>
pub fn as_str(&self) -> Result<&str, LiteStrErr>
Returns the stored string as &str.
pub fn from_bytes(bytes: &[u8]) -> Result<Self, LiteStrErr>
pub fn to_bytes(&self) -> [u8; N]
Trait Implementations§
Source§impl<'de, const N: usize> Deserialize<'de> for LiteStr<N>
Available on crate feature serde only.
impl<'de, const N: usize> Deserialize<'de> for LiteStr<N>
Available on crate feature
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<const N: usize> PartialEq for LiteStr<N>
impl<const N: usize> PartialEq for LiteStr<N>
Source§impl<const N: usize> Write for LiteStr<N>
impl<const N: usize> Write for LiteStr<N>
impl<const N: usize> Copy for LiteStr<N>
impl<const N: usize> Eq for LiteStr<N>
impl<const N: usize> StructuralPartialEq for LiteStr<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for LiteStr<N>
impl<const N: usize> RefUnwindSafe for LiteStr<N>
impl<const N: usize> Send for LiteStr<N>
impl<const N: usize> Sync for LiteStr<N>
impl<const N: usize> Unpin for LiteStr<N>
impl<const N: usize> UnsafeUnpin for LiteStr<N>
impl<const N: usize> UnwindSafe for LiteStr<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.