ClosureOnce

Struct ClosureOnce 

Source
pub struct ClosureOnce { /* private fields */ }
Expand description

A closure that owns needs-drop data.

This allows the closure’s callback to take ownership of the data, in which case the userdata will be gone if called again.

Implementations§

Source§

impl ClosureOnce

Source

pub fn new<U: Any, R>( cif: Cif, callback: CallbackOnce<U, R>, userdata: U, ) -> Self

Creates a new closure with owned userdata.

§Arguments
  • cif — describes the calling convention and argument and result types
  • callback — the function to call when the closure is invoked
  • userdata — the value to pass to callback along with the arguments when the closure is called
§Result

The new closure.

Source

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

Obtains the callable code pointer for a closure.

§Safety

The result needs to be transmuted to the correct type before it can be called. If the type is wrong then undefined behavior will result.

Source

pub unsafe fn instantiate_code_ptr<T>(&self) -> &T

Transmutes the callable code pointer for a closure to a reference to any type. This is intended to be used to transmute it to its correct function type in order to call it.

§Safety

This method allows transmuting to a reference to any sized type, and cannot check whether the code pointer actually has that type. If the type is wrong then undefined behavior will result.

Trait Implementations§

Source§

impl Debug for ClosureOnce

Source§

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

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

impl Drop for ClosureOnce

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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