#[repr(C)]pub struct Nul<A>(/* private fields */);
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§
Source§impl<A> Nul<A>
impl<A> Nul<A>
Sourcepub fn as_mut_ptr(&mut self) -> *mut A
pub fn as_mut_ptr(&mut self) -> *mut A
Return a mutable pointer to the start of the array.
Sourcepub const unsafe fn new_unchecked(p: *const A) -> &'static Self
pub const unsafe fn new_unchecked(p: *const A) -> &'static Self
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.
Sourcepub unsafe fn new_unchecked_mut(p: *mut A) -> &'static mut Self
pub unsafe fn new_unchecked_mut(p: *mut A) -> &'static mut Self
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.
Sourcepub fn get_mut(&mut self, i: usize) -> Option<&mut A>
pub fn get_mut(&mut self, i: usize) -> Option<&mut A>
Get element at given position, mutably. O(n)
to check bounds
Sourcepub fn split_at_mut(&mut self, i: usize) -> (&mut [A], &mut Self)
pub fn split_at_mut(&mut self, i: usize) -> (&mut [A], &mut Self)
Sourcepub fn try_split_at(&self, i: usize) -> Option<(&[A], &Self)>
pub fn try_split_at(&self, i: usize) -> Option<(&[A], &Self)>
Split array at given position; return None
if index out of bounds.
Sourcepub fn try_split_at_mut(&mut self, i: usize) -> Option<(&mut [A], &mut Self)>
pub fn try_split_at_mut(&mut self, i: usize) -> Option<(&mut [A], &mut Self)>
Split array at given position, mutably; return None
if index out of bounds.