pub struct RcBlock<F: ?Sized> { /* private fields */ }
Expand description
A reference-counted Objective-C block that is stored on the heap.
This is a smart pointer that Deref
s to Block
.
The generic type F
must be a dyn
Fn
that implements the
BlockFn
trait, just like described in Block
’s documentation.
§Memory-layout
This is guaranteed to have the same size and alignment as a pointer to a
block (i.e. same size as *const Block<A, R>
).
Additionally, it participates in the null-pointer optimization, that is,
Option<RcBlock<A, R>>
is guaranteed to have the same size as
RcBlock<A, R>
.
Implementations§
source§impl<F: ?Sized> RcBlock<F>
impl<F: ?Sized> RcBlock<F>
sourcepub unsafe fn from_raw(ptr: *mut Block<F>) -> Option<Self>
pub unsafe fn from_raw(ptr: *mut Block<F>) -> Option<Self>
Construct an RcBlock
from the given block pointer by taking
ownership.
This will return None
if the pointer is NULL.
§Safety
The given pointer must point to a valid block, the parameter and return types must be correct, and the block must have a +1 reference / retain count from somewhere else.
Additionally, the block must be safe to call (or, if it is not, then
you must treat every call to the block as unsafe
).
sourcepub unsafe fn copy(ptr: *mut Block<F>) -> Option<Self>
pub unsafe fn copy(ptr: *mut Block<F>) -> Option<Self>
Construct an RcBlock
from the given block pointer.
The block will be copied, and have its reference-count increased by one.
This will return None
if the pointer is NULL, or if an allocation
failure occurred.
See Block::copy
for a safe alternative when you already know the
block pointer is valid.
§Safety
The given pointer must point to a valid block, and the parameter and return types must be correct.
Additionally, the block must be safe to call (or, if it is not, then
you must treat every call to the block as unsafe
).
Methods from Deref<Target = Block<F>>§
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.