intuicio_ffi

Struct FfiCodePtr

Source
#[repr(C)]
pub struct FfiCodePtr(pub *mut c_void);
Expand description

Wraps a function pointer of unknown type.

This is used to make the API a bit easier to understand, and as a simple type lint. As a repr(C) struct of one element, it should be safe to transmute between CodePtr and *mut c_void, or between collections thereof.

Tuple Fields§

§0: *mut c_void

Implementations§

Source§

impl CodePtr

Source

pub fn from_fun(fun: unsafe extern "C" fn()) -> CodePtr

Initializes a code pointer from a function pointer.

This is useful mainly for talking to C APIs that take untyped callbacks specified in the API as having type void(*)().

Source

pub fn from_ptr(fun: *const c_void) -> CodePtr

Initializes a code pointer from a void pointer.

This is the other common type used in APIs (or at least in libffi) for untyped callback arguments.

Source

pub fn as_fun(&self) -> &unsafe extern "C" fn()

Gets the code pointer typed as a C function pointer.

This is useful mainly for talking to C APIs that take untyped callbacks specified in the API as having type void(*)().

§Safety

There is no checking that the returned type reflects the actual parameter and return types of the function. Unless the C function actually has type void(*)(), it will need to be cast before it is called.

Source

pub unsafe fn as_safe_fun(&self) -> &extern "C" fn()

Gets the code pointer typed as a “safe” C function pointer.

This is useful mainly for talking to C APIs that take untyped callbacks specified in the API as having type void(*)().

§Safety

There isn’t necessarily anything actually safe about the resulting function pointer—it’s up to the caller to know what they’re doing within the unsafety boundary, or undefined behavior may result. In particular, there is no checking that the returned type reflects the actual parameter and return types of the function. Unless the C function actually has type void(*)(), it will need to be cast before it is called.

Source

pub fn as_ptr(self) -> *const c_void

Gets the code pointer typed as a const void*.

This is the other common type used in APIs (or at least in libffi) for untyped callback arguments.

Source

pub fn as_mut_ptr(self) -> *mut c_void

Gets the code pointer typed as a void*.

This is the other common type used in APIs (or at least in libffi) for untyped callback arguments.

Trait Implementations§

Source§

impl Clone for CodePtr

Source§

fn clone(&self) -> CodePtr

Returns a copy 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 CodePtr

Source§

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

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

impl Hash for CodePtr

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Copy for CodePtr

Auto Trait Implementations§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> Finalize for T

Source§

unsafe fn finalize_raw(data: *mut ())

Safety 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.