[][src]Struct null_terminated::Nul

#[repr(C)]
pub struct Nul<A>(_, _);

Generic unsized null-terminated array

&Nul<A> is a thin pointer, so it can be readily used with FFI.

Examples

One can safely take views of null-terminated slices with TryFrom::try_from:

extern "C" {
    fn c_f(path: *const u8) -> i32;
}

fn f(path: &[u8]) -> Result<i32, ()> {
    <&Nul<u8> as ::fallible::TryFrom<_>>::try_from(path)
        .map(|path| unsafe { c_f(path.as_ptr()) })
}

Methods

impl<A> Nul<A>[src]

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

Return a pointer to the start of the array.

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

Return a mutable pointer to the start of the array.

Important traits for Iter<'a, A>
pub const fn iter(&self) -> Iter<A>[src]

Iterate over array elements.

Important traits for IterMut<'a, A>
pub fn iter_mut(&mut self) -> IterMut<A>[src]

Iterate over array elements, mutably.

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

Create a reference to a null-terminated array, given a pointer to its start.

The caller must make sure the argument does, in fact, point to a null-terminated array, 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 A) -> &'static mut Self[src]

Create a mutable reference to a null-terminated array, given a pointer to its start.

The caller must make sure the argument does, in fact, point to a null-terminated array, and the returned reference not live longer than the array it refers to. These requirements are not checked.

pub fn len(&self) -> usize[src]

Return array length. O(n)

pub fn get(&self, i: usize) -> Option<&A>[src]

Get element at given position. O(n) to check bounds

pub fn get_mut(&mut self, i: usize) -> Option<&mut A>[src]

Get element at given position, mutably. O(n) to check bounds

pub fn split_at(&self, i: usize) -> (&[A], &Self)[src]

Split array at given position.

Panics

Panics if index out of bounds.

pub fn split_at_mut(&mut self, i: usize) -> (&mut [A], &mut Self)[src]

Split array at given position, mutably.

Panics

Panics if index out of bounds.

pub fn try_split_at(&self, i: usize) -> Option<(&[A], &Self)>[src]

Split array at given position; return None if index out of bounds.

pub fn try_split_at_mut(&mut self, i: usize) -> Option<(&mut [A], &mut Self)>[src]

Split array at given position, mutably; return None if index out of bounds.

Trait Implementations

impl<A: PartialEq> PartialEq<Nul<A>> for Nul<A>[src]

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

This method tests for !=.

impl<A: Eq> Eq for Nul<A>[src]

impl<A: Ord> Ord for Nul<A>[src]

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

Compares and returns the maximum of two values. Read more

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

Compares and returns the minimum of two values. Read more

default fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<A: PartialOrd> PartialOrd<Nul<A>> for Nul<A>[src]

#[must_use]
default 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]
default 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]
default 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]
default 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, A> From<Iter<'a, A>> for &'a Nul<A>[src]

impl<'a, A> From<IterMut<'a, A>> for &'a mut Nul<A>[src]

impl<A: Debug> Debug for Nul<A>[src]

impl Display for Nul<char>[src]

impl<A, I> Index<I> for Nul<A> where
    [A]: Index<I>, 
[src]

type Output = <[A] as Index<I>>::Output

The returned type after indexing.

impl<A, I> IndexMut<I> for Nul<A> where
    [A]: IndexMut<I>, 
[src]

impl<A: Hash> Hash for Nul<A>[src]

default 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<'a, A> IntoIterator for &'a Nul<A>[src]

type Item = &'a A

The type of the elements being iterated over.

type IntoIter = Iter<'a, A>

Which kind of iterator are we turning this into?

impl<'a, A> IntoIterator for &'a mut Nul<A>[src]

type Item = &'a mut A

The type of the elements being iterated over.

type IntoIter = IterMut<'a, A>

Which kind of iterator are we turning this into?

impl<A> AsRef<Nul<A>> for Nul<A>[src]

impl<'a, A> TryFrom<&'a [A]> for &'a Nul<A>[src]

type Error = ()

impl<'a, A> TryFrom<&'a mut [A]> for &'a mut Nul<A>[src]

type Error = ()

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

type Error = Utf8Error

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

type Error = Utf8Error

Auto Trait Implementations

impl<A> Send for Nul<A> where
    A: Send

impl<A> Sync for Nul<A> where
    A: Sync

Blanket Implementations

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto 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, U> Into for T where
    U: From<T>, 
[src]

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

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

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

impl<A, T> TryFrom for T where
    T: From<A>, 
[src]

type Error = Void

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

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