Struct Type

Source
pub struct Type(/* private fields */);
Expand description

Represents a single C type.

§Example

Suppose we have a C struct:

struct my_struct {
    uint16_t f1;
    uint64_t f2;
};

To pass the struct by value via libffi, we need to construct a Type object describing its layout:

use deno_libffi::middle::Type;

let my_struct = Type::structure(vec![
    Type::u64(),
    Type::u16(),
]);

Implementations§

Source§

impl Type

Source

pub fn void() -> Self

Returns the representation of the C void type.

This is used only for the return type of a CIF, not for an argument or struct member.

Source

pub fn u8() -> Self

Returns the unsigned 8-bit numeric type.

Source

pub fn i8() -> Self

Returns the signed 8-bit numeric type.

Source

pub fn u16() -> Self

Returns the unsigned 16-bit numeric type.

Examples found in repository?
examples/types.rs (line 4)
3fn main() {
4    Type::structure(vec![Type::u16(), Type::u16()].into_iter());
5}
Source

pub fn i16() -> Self

Returns the signed 16-bit numeric type.

Source

pub fn u32() -> Self

Returns the unsigned 32-bit numeric type.

Source

pub fn i32() -> Self

Returns the signed 32-bit numeric type.

Source

pub fn u64() -> Self

Returns the unsigned 64-bit numeric type.

Source

pub fn i64() -> Self

Returns the signed 64-bit numeric type.

Source

pub fn usize() -> Self

Returns the C equivalent of Rust usize (u64).

Source

pub fn isize() -> Self

Returns the C equivalent of Rust isize (i64).

Source

pub fn c_schar() -> Self

Returns the C signed char type.

Source

pub fn c_uchar() -> Self

Returns the C unsigned char type.

Source

pub fn c_short() -> Self

Returns the C short type.

Source

pub fn c_ushort() -> Self

Returns the C unsigned short type.

Source

pub fn c_int() -> Self

Returns the C int type.

Source

pub fn c_uint() -> Self

Returns the C unsigned int type.

Source

pub fn c_long() -> Self

Returns the C long type.

Source

pub fn c_ulong() -> Self

Returns the C unsigned long type.

Source

pub fn c_longlong() -> Self

Returns the C longlong type.

Source

pub fn c_ulonglong() -> Self

Returns the C unsigned longlong type.

Source

pub fn f32() -> Self

Returns the C float (32-bit floating point) type.

Source

pub fn f64() -> Self

Returns the C double (64-bit floating point) type.

Source

pub fn pointer() -> Self

Returns the C void* type, for passing any kind of pointer.

Source

pub fn longdouble() -> Self

Returns the C long double (extended-precision floating point) type.

Source

pub fn structure<I>(fields: I) -> Self
where I: IntoIterator<Item = Type>, I::IntoIter: ExactSizeIterator<Item = Type>,

Constructs a structure type whose fields have the given types.

Examples found in repository?
examples/types.rs (line 4)
3fn main() {
4    Type::structure(vec![Type::u16(), Type::u16()].into_iter());
5}
Source

pub fn as_raw_ptr(&self) -> *mut ffi_type

Gets a raw pointer to the underlying ffi_type.

This method may be useful for interacting with the low and raw layers.

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Type

Source§

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

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

impl Drop for Type

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl !Send for Type

§

impl !Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.