Skip to main content

RcBlock

Struct RcBlock 

Source
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>

Source

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.

Source

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

pub fn as_ptr(&self) -> *const c_void

Get a pointer to the block literal to pass to Objective-C.

Source

pub fn into_raw(self) -> *const c_void

Consume the block, preventing its destructor from running.

Use this after passing the block to Metal/Objective-C APIs that will retain the block internally. The block runtime will handle cleanup when the retain count reaches zero.

Source§

impl RcBlock<Box<dyn Fn() + Send>>

Source

pub fn from_fn<F>(f: F) -> Self
where F: Fn() + Send + 'static,

Create a block from a closure taking no arguments.

Source§

impl RcBlock<Box<dyn Fn(*mut c_void) + Send>>

Source

pub fn from_fn<F>(f: F) -> Self
where F: Fn(*mut c_void) + Send + 'static,

Create a block from a closure taking one pointer argument.

Source

pub fn from_fn_heap<F>(f: F) -> HeapOneArgBlock
where F: Fn(*mut c_void) + Send + 'static,

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.

Source§

impl RcBlock<Box<dyn Fn(*mut c_void, *mut c_void) + Send>>

Source

pub fn from_fn<F>(f: F) -> Self
where F: Fn(*mut c_void, *mut c_void) + Send + 'static,

Create a block from a closure taking two pointer arguments.

This matches the C++ pattern:

using NewLibraryCompletionHandler = void (^)(MTL::Library*, NS::Error*);
Source§

impl RcBlock<Box<dyn Fn(*mut c_void, *mut c_void, *mut c_void) + Send>>

Source

pub fn from_fn<F>(f: F) -> Self
where F: Fn(*mut c_void, *mut c_void, *mut c_void) + Send + 'static,

Create a block from a closure taking three pointer arguments.

This matches the C++ pattern:

using NewRenderPipelineStateWithReflectionCompletionHandler =
    void (^)(MTL::RenderPipelineState*, MTL::RenderPipelineReflection*, NS::Error*);
Source§

impl RcBlock<Box<dyn Fn(*mut c_void, u64) + Send>>

Source

pub fn from_fn<F>(f: F) -> Self
where F: Fn(*mut c_void, u64) + Send + 'static,

Create a block for SharedEvent notifications.

This matches the C++ pattern for event signaling.

Source§

impl RcBlock<Box<dyn Fn(*mut c_void, usize) + Send>>

Source

pub fn from_fn<F>(f: F) -> Self
where F: Fn(*mut c_void, usize) + Send + 'static,

Create a block for buffer deallocation.

The closure receives the buffer pointer and its size.

Source§

impl RcBlock<Box<dyn Fn(*mut c_void, *mut c_void, isize, *mut c_void) + Send>>

Source

pub fn from_fn<F>(f: F) -> Self
where F: Fn(*mut c_void, *mut c_void, isize, *mut c_void) + Send + 'static,

Create a block for log handling.

The closure receives (subsystem, category, level, message).

Auto Trait Implementations§

§

impl<Closure> Freeze for RcBlock<Closure>
where Closure: Freeze,

§

impl<Closure> RefUnwindSafe for RcBlock<Closure>
where Closure: RefUnwindSafe,

§

impl<Closure> !Send for RcBlock<Closure>

§

impl<Closure> !Sync for RcBlock<Closure>

§

impl<Closure> Unpin for RcBlock<Closure>
where Closure: Unpin,

§

impl<Closure> UnwindSafe for RcBlock<Closure>
where Closure: UnwindSafe,

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.