Struct CArray

Source
#[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<U: AsRust<V> + 'static, V> AsRust<Vec<V>> for CArray<U>

Source§

impl<T> CDrop for CArray<T>

Source§

fn do_drop(&mut self) -> Result<(), CDropError>

Source§

impl<U: CReprOf<V> + CDrop, V: 'static> CReprOf<Vec<V>> for CArray<U>

Source§

fn c_repr_of(input: Vec<V>) -> Result<Self, CReprOfError>

Source§

impl<T: Debug> Debug for CArray<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for CArray<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> RawPointerConverter<CArray<T>> for CArray<T>

Source§

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>

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>

Takes back control of a raw pointer created by Self::into_raw_pointer. Read more
Source§

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 more
Source§

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 more
Source§

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 more

Auto 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RawBorrow<T> for T

Source§

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 more
Source§

impl<T> RawBorrowMut<T> for T

Source§

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.