Struct null_terminated::NulStr[][src]

#[repr(transparent)]
pub struct NulStr(_);
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

impl NulStr[src]

pub const unsafe fn new_unchecked(p: *const u8) -> &'static Self[src]

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.

pub unsafe fn new_unchecked_mut(p: *mut u8) -> &'static mut Self[src]

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.

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

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

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

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

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

Return a pointer to the start of the string.

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

Return a mutable pointer to the start of the string.

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

Notable traits for Chars<'a>

impl<'a> Iterator for Chars<'a> type Item = char;
[src]

Iterate over the characters of the string.

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

Notable traits for CharIndices<'a>

impl<'a> Iterator for CharIndices<'a> type Item = (usize, char);
[src]

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

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

Return whether the given byte position is a character boundary.

Trait Implementations

impl Debug for NulStr[src]

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

Formats the value using the given formatter. Read more

impl Display for NulStr[src]

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

Formats the value using the given formatter. Read more

impl Hash for NulStr[src]

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

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl Index<RangeFull> for NulStr[src]

type Output = str

The returned type after indexing.

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

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

impl IndexMut<RangeFull> for NulStr[src]

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

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

impl Ord for NulStr[src]

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

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

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<NulStr> for NulStr[src]

fn eq(&self, other: &NulStr) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &NulStr) -> bool[src]

This method tests for !=.

impl PartialOrd<NulStr> for NulStr[src]

fn partial_cmp(&self, other: &NulStr) -> Option<Ordering>[src]

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> TryFrom<&'a Nul<u8>> for &'a NulStr[src]

type Error = Utf8Error

The type returned in the event of a conversion error.

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

Performs the conversion.

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

type Error = Utf8Error

The type returned in the event of a conversion error.

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

Performs the conversion.

impl Eq for NulStr[src]

impl StructuralEq for NulStr[src]

impl StructuralPartialEq for NulStr[src]

Auto Trait Implementations

impl Send for NulStr

impl !Sized for NulStr

impl Sync for NulStr

impl !Unpin for NulStr

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more