[][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, 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: PartialEq> PartialEq<Nul<A>> for Nul<A>[src]

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

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

impl<A: PartialOrd> PartialOrd<Nul<A>> for Nul<A>[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]

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> !Unpin for Nul<A>

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

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

Blanket Implementations

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

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

type Error = !

The type returned in the event of a conversion error.

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

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> Borrow<T> for T where
    T: ?Sized
[src]

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

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

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

type Error = Void

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

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