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
impl ClosureOnce
Sourcepub fn new<U: Any, R>(
cif: Cif,
callback: CallbackOnce<U, R>,
userdata: U,
) -> Self
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 typescallback
— the function to call when the closure is invokeduserdata
— the value to pass tocallback
along with the arguments when the closure is called
§Result
The new closure.
Sourcepub fn code_ptr(&self) -> &unsafe extern "C" fn()
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.
Sourcepub unsafe fn instantiate_code_ptr<T>(&self) -> &T
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.