pub struct CStrBuf<const N: usize>(/* private fields */);Expand description
A fixed-size narrow string buffer inside a struct (char name[N]),
holding a string up to the first NUL.
§Examples
use imping_runtime::CStrBuf;
let mut tag = CStrBuf::<8>::new();
tag.set("Héllo, world");
assert_eq!(tag.to_string_lossy(), "Héllo,"); // at most 7 bytes, then the NULImplementations§
Source§impl<const N: usize> CStrBuf<N>
impl<const N: usize> CStrBuf<N>
Sourcepub fn to_bytes(&self) -> &[u8] ⓘ
pub fn to_bytes(&self) -> &[u8] ⓘ
Returns the string’s bytes: up to the first NUL, or the whole buffer if it has none.
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Returns the string as UTF-8, with invalid sequences replaced by �.
Sourcepub fn to_string_ansi(&self) -> String
pub fn to_string_ansi(&self) -> String
Decodes the string with the system’s ANSI code page.
On other platforms, the same as to_string_lossy.
Sourcepub fn set(&mut self, value: &str)
pub fn set(&mut self, value: &str)
Stores value as UTF-8, truncated to fit before the terminating NUL.
Truncation never splits a character. A NUL in value ends it, and the
rest of the buffer is zeroed.
Sourcepub fn as_array_mut(&mut self) -> &mut [u8; N]
pub fn as_array_mut(&mut self) -> &mut [u8; N]
Returns the whole buffer, to write to it directly.
Trait Implementations§
impl<const N: usize> Copy for CStrBuf<N>
impl<const N: usize> Eq for CStrBuf<N>
impl<const N: usize> Plain for CStrBuf<N>
impl<const N: usize> StructuralPartialEq for CStrBuf<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for CStrBuf<N>
impl<const N: usize> RefUnwindSafe for CStrBuf<N>
impl<const N: usize> Send for CStrBuf<N>
impl<const N: usize> Sync for CStrBuf<N>
impl<const N: usize> Unpin for CStrBuf<N>
impl<const N: usize> UnsafeUnpin for CStrBuf<N>
impl<const N: usize> UnwindSafe for CStrBuf<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