pub struct NulStr(/* private fields */);
Expand description
Null-terminated UTF-8 encoded string
&NulStr
is a thin pointer, so it can be readily used with FFI.
One can convert from &Nul<u8>
to &NulStr
with try_from
, which checks whether its
argument is valid UTF-8.
Implementations§
Source§impl NulStr
impl NulStr
Sourcepub const unsafe fn new_unchecked(p: *const u8) -> &'static Self
pub const unsafe fn new_unchecked(p: *const u8) -> &'static Self
Create a reference to a null-terminated string, given a pointer to its start.
The caller must make sure the argument does, in fact, point to a null-terminated string; the string is valid UTF-8; and the returned reference not live longer than the array it refers to. These requirements are not checked.
Sourcepub unsafe fn new_unchecked_mut(p: *mut u8) -> &'static mut Self
pub unsafe fn new_unchecked_mut(p: *mut u8) -> &'static mut Self
Create a mutable reference to a null-terminated string, given a pointer to its start.
The caller must make sure the argument does, in fact, point to a null-terminated string; the string is valid UTF-8; and the returned reference not live longer than the array it refers to. These requirements are not checked.
Sourcepub fn as_bytes_mut(&mut self) -> &mut Nul<u8>
pub fn as_bytes_mut(&mut self) -> &mut Nul<u8>
Return a mutable slice of the UTF-8 code bytes of the string.
Sourcepub fn as_mut_ptr(&mut self) -> *const u8
pub fn as_mut_ptr(&mut self) -> *const u8
Return a mutable pointer to the start of the string.
Sourcepub fn char_indices(&self) -> CharIndices<'_> ⓘ
pub fn char_indices(&self) -> CharIndices<'_> ⓘ
Iterate over the characters of the string and their byte positions.
Sourcepub fn is_char_boundary(&self, k: usize) -> bool
pub fn is_char_boundary(&self, k: usize) -> bool
Return whether the given byte position is a character boundary.