[][src]Struct toolshed::NulTermStr

pub struct NulTermStr<'arena>(_);

A wrapper around a str slice that has an extra 0 byte allocated following its contents.

Methods

impl<'arena> NulTermStr<'arena>[src]

pub unsafe fn byte_unchecked(&self, index: usize) -> u8[src]

Read byte at a given index. This does not check for length boundaries, but is guaranteed to return 0 for index equal to the length.

This can be a very useful optimization when reading a long string one byte at a time until termination, if checking for 0 can replace what would otherwise have to be length checks.

let arena = Arena::new();
let str = arena.alloc_nul_term_str("foo");

// We can safely get the underlying `&str` at any time.
assert_eq!(&str[..], "foo");

unsafe {
    // First 3 bytes are known to us
    assert_eq!(str.byte_unchecked(0), b'f');
    assert_eq!(str.byte_unchecked(1), b'o');
    assert_eq!(str.byte_unchecked(2), b'o');

    // Following is safe and guaranteed to be '0'
    assert_eq!(str.byte_unchecked(3), 0);

    // Reading index 4 would be undefined behavior!
}

Trait Implementations

impl<'arena> PartialEq<NulTermStr<'arena>> for NulTermStr<'arena>[src]

impl<'arena> Copy for NulTermStr<'arena>[src]

impl<'arena> Clone for NulTermStr<'arena>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'arena> AsRef<str> for NulTermStr<'arena>[src]

impl<'arena> From<NulTermStr<'arena>> for &'arena str[src]

impl<'arena> Deref for NulTermStr<'arena>[src]

type Target = &'arena str

The resulting type after dereferencing.

impl<'arena> Debug for NulTermStr<'arena>[src]

impl<'arena> Display for NulTermStr<'arena>[src]

Auto Trait Implementations

impl<'arena> Send for NulTermStr<'arena>

impl<'arena> Sync for NulTermStr<'arena>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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

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

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