MeasuredNullTermStr

Struct MeasuredNullTermStr 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub const fn as_bytes(&self) -> &[u8]

Return a slice of the internal string data, without trailing null byte.

Source

pub fn as_os_str(&self) -> &OsStr

Translate this data to a platform-specific string, suitable for translation to Path.

Source

pub const fn len(&self) -> usize

Length of the internal string data, without trailing null byte.

Source

pub const fn is_empty(&self) -> bool

Whether the internal string data points to a single null byte.

Source

pub const fn len_with_nul(&self) -> NonZeroUsize

Length of the internal string data, with trailing null byte.

Source

pub const fn as_bytes_with_nul(&self) -> &[u8]

Return a slice of the internal string data, with trailing null byte.

Source

pub const fn as_unmeasured<'s>(&'s self) -> NullTermStr<'s>

Retrieve the internal string data, which may be converted to a pointer again.

Source

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

Source§

impl Borrow<MeasuredNullTermStr> for NullTermString

Source§

fn borrow(&self) -> &MeasuredNullTermStr

Immutably borrows from an owned value. Read more
Source§

impl Debug for MeasuredNullTermStr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'s> From<&'s [u8]> for &'s MeasuredNullTermStr

Source§

fn from(s: &'s [u8]) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<&'s CStr> for &'s MeasuredNullTermStr

Source§

fn from(s: &'s CStr) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<&'s MeasuredNullTermStr> for &'s [u8]

Source§

fn from(s: &'s MeasuredNullTermStr) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<&'s MeasuredNullTermStr> for &'s CStr

Source§

fn from(s: &'s MeasuredNullTermStr) -> &'s CStr

Converts to this type from the input type.
Source§

impl Hash for MeasuredNullTermStr

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
Source§

impl Ord for MeasuredNullTermStr

Source§

fn cmp(&self, rhs: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq for MeasuredNullTermStr

Source§

fn eq(&self, rhs: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for MeasuredNullTermStr

Source§

fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToOwned for MeasuredNullTermStr

Source§

type Owned = NullTermString

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl Eq for MeasuredNullTermStr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more