[][src]Struct libffi::low::CodePtr

#[repr(C)]
pub struct CodePtr(pub *mut c_void);

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.

Methods

impl CodePtr[src]

pub fn from_fun(fun: unsafe extern "C" fn()) -> Self[src]

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(*)().

pub fn from_ptr(fun: *const c_void) -> Self[src]

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.

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

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.

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

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.

pub fn as_ptr(self) -> *const c_void[src]

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.

pub fn as_mut_ptr(self) -> *mut c_void[src]

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

impl Clone for CodePtr[src]

impl Copy for CodePtr[src]

impl Debug for CodePtr[src]

impl Hash for CodePtr[src]

Auto Trait Implementations

impl !Send for CodePtr

impl !Sync for CodePtr

impl Unpin for CodePtr

impl UnwindSafe for CodePtr

impl RefUnwindSafe for CodePtr

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]