Struct null_terminated::Nul[][src]

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

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 ::std::convert::TryFrom<_>>::try_from(path)
        .map(|path| unsafe { c_f(path.as_ptr()) })
}

Implementations

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.

pub const fn iter(&self) -> Iter<'_, A>

Notable traits for Iter<'a, A>

impl<'a, A: 'a> Iterator for Iter<'a, A> type Item = &'a A;
[src]

Iterate over array elements.

pub fn iter_mut(&mut self) -> IterMut<'_, A>

Notable traits for IterMut<'a, A>

impl<'a, A: 'a> Iterator for IterMut<'a, A> type Item = &'a mut 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> AsRef<Nul<A>> for Nul<A>[src]

fn as_ref(&self) -> &Self[src]

Performs the conversion.

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

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

Formats the value using the given formatter. Read more

impl Display for Nul<char>[src]

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

Formats the value using the given formatter. Read more

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

fn from(it: Iter<'a, A>) -> Self[src]

Performs the conversion.

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

fn from(it: IterMut<'a, A>) -> Self[src]

Performs the conversion.

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

fn hash<H: Hasher>(&self, h: &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<A, I> Index<I> for Nul<A> where
    [A]: Index<I>, 
[src]

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

The returned type after indexing.

fn index(&self, i: I) -> &Self::Output[src]

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

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

fn index_mut(&mut self, i: I) -> &mut Self::Output[src]

Performs the mutable indexing (container[index]) operation. 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?

fn into_iter(self) -> Iter<'a, A>

Notable traits for Iter<'a, A>

impl<'a, A: 'a> Iterator for Iter<'a, A> type Item = &'a A;
[src]

Creates an iterator from a value. Read more

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?

fn into_iter(self) -> IterMut<'a, A>

Notable traits for IterMut<'a, A>

impl<'a, A: 'a> Iterator for IterMut<'a, A> type Item = &'a mut A;
[src]

Creates an iterator from a value. Read more

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

fn cmp(&self, other: &Self) -> 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<A: PartialEq> PartialEq<Nul<A>> for Nul<A>[src]

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

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

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

This method tests for !=.

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

fn partial_cmp(&self, other: &Self) -> 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, A> TryFrom<&'a [A]> for &'a Nul<A>[src]

type Error = ()

The type returned in the event of a conversion error.

fn try_from(xs: &'a [A]) -> Result<Self, ()>[src]

Performs the conversion.

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

type Error = ()

The type returned in the event of a conversion error.

fn try_from(xs: &'a mut [A]) -> Result<Self, ()>[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<A: Eq> Eq for Nul<A>[src]

Auto Trait Implementations

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

impl<A> !Sized for Nul<A>

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

impl<A> !Unpin for Nul<A>

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

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.