pub struct RcBlock<Closure> { /* private fields */ }Expand description
A reference-counted block wrapping a Rust closure.
This structure matches the Clang blocks ABI exactly, allowing Rust closures to be passed to Objective-C APIs that expect block parameters.
Implementations§
Source§impl<Closure> RcBlock<Closure>
impl<Closure> RcBlock<Closure>
Sourcepub unsafe fn new(closure: Closure, invoke: *const c_void) -> Self
pub unsafe fn new(closure: Closure, invoke: *const c_void) -> Self
Create a new block with the specified invoke function.
§Safety
The invoke function pointer must have the correct calling convention
and signature for the block type. The first parameter must be a pointer
to the BlockLiteral.
Sourcepub unsafe fn new_heap(closure: Closure, invoke: *const c_void) -> Box<Self>
pub unsafe fn new_heap(closure: Closure, invoke: *const c_void) -> Box<Self>
Create a new heap-allocated block with the specified invoke function.
This allocates the block on the heap so it can be safely passed to
Objective-C APIs that retain the block. The returned pointer should
be passed to as_heap_ptr() to get the block pointer.
§Safety
The invoke function pointer must have the correct calling convention
and signature for the block type.
Source§impl RcBlock<Box<dyn Fn(*mut c_void) + Send>>
impl RcBlock<Box<dyn Fn(*mut c_void) + Send>>
Sourcepub fn from_fn_heap<F>(f: F) -> HeapOneArgBlock
pub fn from_fn_heap<F>(f: F) -> HeapOneArgBlock
Create a heap-allocated block from a closure taking one pointer argument.
Use this for blocks that need to outlive the current scope, such as completion handlers passed to Metal APIs.