Struct NulStr

Source
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

Source

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.

Source

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.

Source

pub fn as_bytes(&self) -> &Nul<u8>

Return a slice of the UTF-8 code bytes of the string.

Source

pub fn as_bytes_mut(&mut self) -> &mut Nul<u8>

Return a mutable slice of the UTF-8 code bytes of the string.

Source

pub fn as_ptr(&self) -> *const u8

Return a pointer to the start of the string.

Source

pub fn as_mut_ptr(&mut self) -> *const u8

Return a mutable pointer to the start of the string.

Source

pub fn chars(&self) -> Chars<'_>

Iterate over the characters of the string.

Source

pub fn char_indices(&self) -> CharIndices<'_>

Iterate over the characters of the string and their byte positions.

Source

pub fn is_char_boundary(&self, k: usize) -> bool

Return whether the given byte position is a character boundary.

Trait Implementations§

Source§

impl Debug for NulStr

Source§

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

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

impl Display for NulStr

Source§

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

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

impl Hash for NulStr

Source§

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

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

impl Index<RangeFull> for NulStr

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, _: RangeFull) -> &str

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFull> for NulStr

Source§

fn index_mut(&mut self, _: RangeFull) -> &mut str

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Ord for NulStr

Source§

fn cmp(&self, other: &NulStr) -> Ordering

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

impl PartialEq for NulStr

Source§

fn eq(&self, other: &NulStr) -> 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 NulStr

Source§

fn partial_cmp(&self, other: &NulStr) -> 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<'a> TryFrom<&'a Nul<u8>> for &'a NulStr

Source§

type Error = Utf8Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: &'a Nul<u8>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a mut Nul<u8>> for &'a mut NulStr

Source§

type Error = Utf8Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: &'a mut Nul<u8>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for NulStr

Source§

impl StructuralPartialEq for NulStr

Auto Trait Implementations§

§

impl !Freeze for NulStr

§

impl !RefUnwindSafe for NulStr

§

impl Send for NulStr

§

impl !Sized for NulStr

§

impl Sync for NulStr

§

impl !Unpin for NulStr

§

impl !UnwindSafe for NulStr

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