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>

source

pub fn new(closure: Closure) -> Self
where A: EncodeArguments, R: EncodeReturn, Closure: IntoBlock<'f, A, R> + Clone,

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

source

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.

source

pub fn call(&self, args: F::Args) -> F::Output
where F: BlockFn,

Call the block.

The arguments must be passed as a tuple. The return is the output of the block.

Trait Implementations§

source§

impl<'f, A, R, Closure: Clone> Clone for StackBlock<'f, A, R, Closure>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'f, A, R, Closure> Debug for StackBlock<'f, A, R, Closure>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'f, A, R, Closure> Deref for StackBlock<'f, A, R, Closure>
where A: EncodeArguments, R: EncodeReturn, Closure: IntoBlock<'f, A, R>,

§

type Target = Block<<Closure as IntoBlock<'f, A, R>>::Dyn>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'f, A, R, Closure> RefEncode for StackBlock<'f, A, R, Closure>
where A: EncodeArguments, R: EncodeReturn, Closure: IntoBlock<'f, A, R>,

source§

const ENCODING_REF: Encoding = Encoding::Block

The Objective-C type-encoding for a reference of this type. Read more
source§

impl<'f, A, R, Closure: Copy> Copy for StackBlock<'f, A, R, Closure>

Auto Trait Implementations§

§

impl<'f, A, R, Closure> Freeze for StackBlock<'f, A, R, Closure>
where Closure: Freeze,

§

impl<'f, A, R, Closure> !RefUnwindSafe for StackBlock<'f, A, R, Closure>

§

impl<'f, A, R, Closure> !Send for StackBlock<'f, A, R, Closure>

§

impl<'f, A, R, Closure> !Sync for StackBlock<'f, A, R, Closure>

§

impl<'f, A, R, Closure> Unpin for StackBlock<'f, A, R, Closure>
where Closure: Unpin,

§

impl<'f, A, R, Closure> !UnwindSafe for StackBlock<'f, A, R, Closure>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.
source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,