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
Return a mutable pointer to the start of the array.
Iterate over array elements.
Iterate over array elements, mutably.
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.
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.
Get element at given position, mutably. O(n)
to check bounds
Split array at given position; return None
if index out of bounds.
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more