Struct block2::StackBlock
source · #[repr(C)]pub struct StackBlock<'f, A, R, Closure> { /* private fields */ }Expand description
An Objective-C block constructed on the stack.
This is a smart pointer that Derefs to Block.
§Type parameters
The type parameters for this is a bit complex due to trait system limitations. Usually, you will not need to specify them, as the compiler should be able to infer them.
- The lifetime
'f, which is the lifetime of the block. - The parameter
A, which is a tuple representing the parameters to the block. - The parameter
R, which is the return type of the block. - The parameter
Closure, which is the contained closure type. This is usually not nameable, and you will have to use_,impl Fn()or similar.
§Memory layout
The memory layout of this type is not guaranteed.
That said, it will always be safe to reintepret pointers to this as a
pointer to a Block with the corresponding dyn Fn type.
Implementations§
source§impl<'f, A, R, Closure> StackBlock<'f, A, R, Closure>
impl<'f, A, R, Closure> StackBlock<'f, A, R, Closure>
sourcepub fn new(closure: Closure) -> Self
pub fn new(closure: Closure) -> Self
Construct a StackBlock with the given closure.
Note that this requires Clone, as a C block is generally assumed
to be copy-able. If you want to avoid that, put the block directly on
the heap using RcBlock::new.
When the block is called, it will return the value that results from calling the closure.
Methods from Deref<Target = Block<Closure::Dyn>>§
sourcepub fn copy(&self) -> RcBlock<F>
pub fn copy(&self) -> RcBlock<F>
Copy the block onto the heap as an RcBlock.
The behaviour of this function depends on whether the block is from a
RcBlock or a StackBlock. In the former case, it will bump the
reference-count (just as-if you’d Clone’d the RcBlock), in the
latter case it will construct a new RcBlock from the StackBlock.
This distiction should not matter, except for micro-optimizations.