#[repr(C)]pub struct CArray<T> {
pub data_ptr: *const T,
pub size: usize,
}
Expand description
A utility type to represent arrays of the parametrized type. Note that the parametrized type should have a C-compatible representation.
§Example
use ffi_convert::{CReprOf, AsRust, CDrop, CArray};
use libc::c_char;
pub struct PizzaTopping {
pub ingredient: String,
}
#[derive(CDrop, CReprOf, AsRust)]
#[target_type(PizzaTopping)]
pub struct CPizzaTopping {
pub ingredient: *const c_char
}
let toppings = vec![
PizzaTopping { ingredient: "Cheese".to_string() },
PizzaTopping { ingredient: "Ham".to_string() } ];
let ctoppings = CArray::<CPizzaTopping>::c_repr_of(toppings);
Fields§
§data_ptr: *const T
Pointer to the first element of the array
size: usize
Number of elements in the array
Trait Implementations§
Source§impl<T> RawPointerConverter<CArray<T>> for CArray<T>
impl<T> RawPointerConverter<CArray<T>> for CArray<T>
Source§fn into_raw_pointer(self) -> *const CArray<T>
fn into_raw_pointer(self) -> *const CArray<T>
Creates a raw pointer from the value and leaks it, you should use
Self::from_raw_pointer
or Self::drop_raw_pointer
to free the value when you’re done with it.Source§fn into_raw_pointer_mut(self) -> *mut CArray<T>
fn into_raw_pointer_mut(self) -> *mut CArray<T>
Creates a mutable raw pointer from the value and leaks it, you should use
Self::from_raw_pointer_mut
or Self::drop_raw_pointer_mut
to free the value when
you’re done with it.Source§unsafe fn from_raw_pointer(
input: *const CArray<T>,
) -> Result<Self, UnexpectedNullPointerError>
unsafe fn from_raw_pointer( input: *const CArray<T>, ) -> Result<Self, UnexpectedNullPointerError>
Takes back control of a raw pointer created by
Self::into_raw_pointer
. Read moreSource§unsafe fn from_raw_pointer_mut(
input: *mut CArray<T>,
) -> Result<Self, UnexpectedNullPointerError>
unsafe fn from_raw_pointer_mut( input: *mut CArray<T>, ) -> Result<Self, UnexpectedNullPointerError>
Takes back control of a raw pointer created by
Self::into_raw_pointer_mut
. Read moreSource§unsafe fn drop_raw_pointer(
input: *const T,
) -> Result<(), UnexpectedNullPointerError>
unsafe fn drop_raw_pointer( input: *const T, ) -> Result<(), UnexpectedNullPointerError>
Takes back control of a raw pointer created by
Self::into_raw_pointer
and drop it. Read moreSource§unsafe fn drop_raw_pointer_mut(
input: *mut T,
) -> Result<(), UnexpectedNullPointerError>
unsafe fn drop_raw_pointer_mut( input: *mut T, ) -> Result<(), UnexpectedNullPointerError>
Takes back control of a raw pointer created by
Self::into_raw_pointer_mut
and drops it. Read moreAuto Trait Implementations§
impl<T> Freeze for CArray<T>
impl<T> RefUnwindSafe for CArray<T>where
T: RefUnwindSafe,
impl<T> !Send for CArray<T>
impl<T> !Sync for CArray<T>
impl<T> Unpin for CArray<T>
impl<T> UnwindSafe for CArray<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> RawBorrow<T> for T
impl<T> RawBorrow<T> for T
Source§unsafe fn raw_borrow<'a>(
input: *const T,
) -> Result<&'a T, UnexpectedNullPointerError>
unsafe fn raw_borrow<'a>( input: *const T, ) -> Result<&'a T, UnexpectedNullPointerError>
Get a reference on the value behind the pointer or return an error if the pointer is
null
. Read moreSource§impl<T> RawBorrowMut<T> for T
impl<T> RawBorrowMut<T> for T
Source§unsafe fn raw_borrow_mut<'a>(
input: *mut T,
) -> Result<&'a mut T, UnexpectedNullPointerError>
unsafe fn raw_borrow_mut<'a>( input: *mut T, ) -> Result<&'a mut T, UnexpectedNullPointerError>
Get a mutable reference on the value behind the pointer or return an error if the pointer is
null
. Read more