[−][src]Struct toolshed::NulTermStr
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]
fn eq(&self, other: &NulTermStr<'arena>) -> bool
[src]
fn ne(&self, other: &NulTermStr<'arena>) -> bool
[src]
impl<'arena> Copy for NulTermStr<'arena>
[src]
impl<'arena> Clone for NulTermStr<'arena>
[src]
fn clone(&self) -> 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]
fn from(nts: NulTermStr<'arena>) -> &'arena str
[src]
impl<'arena> Deref for NulTermStr<'arena>
[src]
type Target = &'arena str
The resulting type after dereferencing.
fn deref(&self) -> &&'arena str
[src]
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]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,