pub struct MeasuredNullTermStr<'s> { /* private fields */ }Expand description
The more direct analog to ffi::CStr which explicitly knows the length of its string data.
Implementations§
Source§impl<'s> MeasuredNullTermStr<'s>
impl<'s> MeasuredNullTermStr<'s>
Sourcepub const unsafe fn given_measurement(s: NullTermStr<'s>, n: usize) -> Self
pub const unsafe fn given_measurement(s: NullTermStr<'s>, n: usize) -> 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 [u8]) -> Self
pub fn from_bytes_with_nul(s: &'s [u8]) -> 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 [u8]) -> Self
pub const unsafe fn from_bytes_with_nul_unchecked(s: &'s [u8]) -> 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) -> &'s [u8] ⓘ
pub const fn as_bytes(&self) -> &'s [u8] ⓘ
Return a slice of the internal string data, without trailing null byte.
Sourcepub fn as_os_str(&self) -> &'s OsStr
pub fn as_os_str(&self) -> &'s 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) -> usize
pub const fn len_with_nul(&self) -> usize
Length of the internal string data, with trailing null byte.
Sourcepub const fn as_bytes_with_nul(&self) -> &'s [u8] ⓘ
pub const fn as_bytes_with_nul(&self) -> &'s [u8] ⓘ
Return a slice of the internal string data, with trailing null byte.
Sourcepub const fn as_unmeasured(&self) -> NullTermStr<'s>
pub const fn as_unmeasured(&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.
Trait Implementations§
Source§impl AsNullTermStr for MeasuredNullTermStr<'_>
impl AsNullTermStr for MeasuredNullTermStr<'_>
Source§fn as_null_term_str(&self) -> MeasuredNullTermStr<'_>
fn as_null_term_str(&self) -> MeasuredNullTermStr<'_>
Source§impl<'s> Clone for MeasuredNullTermStr<'s>
impl<'s> Clone for MeasuredNullTermStr<'s>
Source§fn clone(&self) -> MeasuredNullTermStr<'s>
fn clone(&self) -> MeasuredNullTermStr<'s>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MeasuredNullTermStr<'_>
impl Debug for MeasuredNullTermStr<'_>
Source§impl<'s> From<&'s [u8]> for MeasuredNullTermStr<'s>
impl<'s> From<&'s [u8]> for MeasuredNullTermStr<'s>
Source§impl<'s> From<&'s CStr> for MeasuredNullTermStr<'s>
impl<'s> From<&'s CStr> for MeasuredNullTermStr<'s>
Source§impl<'s> From<MeasuredNullTermStr<'s>> for &'s [u8]
impl<'s> From<MeasuredNullTermStr<'s>> for &'s [u8]
Source§fn from(s: MeasuredNullTermStr<'s>) -> Self
fn from(s: MeasuredNullTermStr<'s>) -> Self
Source§impl<'s> From<MeasuredNullTermStr<'s>> for &'s CStr
impl<'s> From<MeasuredNullTermStr<'s>> for &'s CStr
Source§fn from(s: MeasuredNullTermStr<'s>) -> &'s CStr
fn from(s: MeasuredNullTermStr<'s>) -> &'s CStr
Source§impl Hash for MeasuredNullTermStr<'_>
impl Hash for MeasuredNullTermStr<'_>
Source§impl Ord for MeasuredNullTermStr<'_>
impl Ord for MeasuredNullTermStr<'_>
Source§impl PartialEq for MeasuredNullTermStr<'_>
impl PartialEq for MeasuredNullTermStr<'_>
Source§impl PartialOrd for MeasuredNullTermStr<'_>
impl PartialOrd for MeasuredNullTermStr<'_>
impl<'s> Copy for MeasuredNullTermStr<'s>
impl Eq for MeasuredNullTermStr<'_>
Auto Trait Implementations§
impl<'s> Freeze for MeasuredNullTermStr<'s>
impl<'s> RefUnwindSafe for MeasuredNullTermStr<'s>
impl<'s> !Send for MeasuredNullTermStr<'s>
impl<'s> !Sync for MeasuredNullTermStr<'s>
impl<'s> Unpin for MeasuredNullTermStr<'s>
impl<'s> UnwindSafe for MeasuredNullTermStr<'s>
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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
key and return true if they are equal.