[−][src]Struct null_terminated::Nul
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]
pub fn split_at_mut(&mut self, i: usize) -> (&mut [A], &mut Self)
[src]
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]
fn eq(&self, other: &Self) -> bool
[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]
fn cmp(&self, other: &Self) -> Ordering
[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]
clamp
)Restrict a value to a certain interval. Read more
impl<A: PartialOrd> PartialOrd<Nul<A>> for Nul<A>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[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]
[A]: Index<I>,
type Output = <[A] as Index<I>>::Output
The returned type after indexing.
fn index(&self, i: I) -> &Self::Output
[src]
impl<A, I> IndexMut<I> for Nul<A> where
[A]: IndexMut<I>,
[src]
[A]: IndexMut<I>,
impl<A: Hash> Hash for Nul<A>
[src]
fn hash<H: Hasher>(&self, h: &mut H)
[src]
default fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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?
ⓘImportant traits for Iter<'a, A>fn into_iter(self) -> Iter<'a, A>
[src]
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?
ⓘImportant traits for IterMut<'a, A>fn into_iter(self) -> IterMut<'a, A>
[src]
impl<A> AsRef<Nul<A>> for Nul<A>
[src]
impl<'a, A> TryFrom<&'a [A]> for &'a Nul<A>
[src]
impl<'a, A> TryFrom<&'a mut [A]> for &'a mut Nul<A>
[src]
impl<'a> TryFrom<&'a Nul<u8>> for &'a NulStr
[src]
impl<'a> TryFrom<&'a mut Nul<u8>> for &'a mut NulStr
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> TryFrom 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 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, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<A, T> TryFrom for T where
T: From<A>,
[src]
T: From<A>,
impl<A, T> TryInto for T where
A: TryFrom<T>,
[src]
A: TryFrom<T>,