pub struct MeasuredNullTermStr { /* private fields */ }Expand description
The more direct analog to ffi::CStr which explicitly knows the length of its string data.
Implementations§
Source§impl MeasuredNullTermStr
impl MeasuredNullTermStr
Sourcepub const unsafe fn given_measurement<'s>(
s: NullTermStr<'s>,
n: usize,
) -> &'s Self
pub const unsafe fn given_measurement<'s>( s: NullTermStr<'s>, n: usize, ) -> &'s Self
Construct a C-style string with a known length.
§Safety
The length n must correctly describe the number of bytes in the string value pointed to by
s, without including the trailing null byte. This is to say that n may be 0, but the
string pointed to by s must be non-null, and must point to a region of memory exactly 1 byte
longer than n.
If the string’s length is not known in advance, use NullTermStr::measure(), which
internally calls this method.
Sourcepub fn from_bytes_with_nul<'s>(s: &'s [u8]) -> &'s Self
pub fn from_bytes_with_nul<'s>(s: &'s [u8]) -> &'s Self
Translate a reference to a byte slice into a measured null-terminated string.
This method will panic if s is empty, if it does not end with a null byte, or if it contains
any internal null bytes.
Sourcepub const unsafe fn from_bytes_with_nul_unchecked<'s>(s: &'s [u8]) -> &'s Self
pub const unsafe fn from_bytes_with_nul_unchecked<'s>(s: &'s [u8]) -> &'s Self
Translate a reference to a byte slice into a measured null-terminated string.
§Safety
s must be non-empty, must end with a null byte, and may not contain any internal null
bytes. Self::from_bytes_with_nul() may be used to validate slices.
Sourcepub const fn as_bytes(&self) -> &[u8] ⓘ
pub const fn as_bytes(&self) -> &[u8] ⓘ
Return a slice of the internal string data, without trailing null byte.
Sourcepub fn as_os_str(&self) -> &OsStr
pub fn as_os_str(&self) -> &OsStr
Translate this data to a platform-specific string, suitable for translation to
Path.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Length of the internal string data, without trailing null byte.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Whether the internal string data points to a single null byte.
Sourcepub const fn len_with_nul(&self) -> NonZeroUsize
pub const fn len_with_nul(&self) -> NonZeroUsize
Length of the internal string data, with trailing null byte.
Sourcepub const fn as_bytes_with_nul(&self) -> &[u8] ⓘ
pub const fn as_bytes_with_nul(&self) -> &[u8] ⓘ
Return a slice of the internal string data, with trailing null byte.
Sourcepub const fn as_unmeasured<'s>(&'s self) -> NullTermStr<'s>
pub const fn as_unmeasured<'s>(&'s self) -> NullTermStr<'s>
Retrieve the internal string data, which may be converted to a pointer again.
Sourcepub fn clone_into(&self, v: &mut NullTermString)
pub fn clone_into(&self, v: &mut NullTermString)
Allocate the necessary space in v and copy over the internal string data.
v’s length will be reset to the length of the internal string data, although it will not
reallocate the underlying vector.