docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

bare::ffi::objc::block

本頁內容

API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。

Nabi closures as Objective-C blocks, laid out as the Apple block ABI says.

A block holds one word: the address of a pinned GC cell holding the closure. Pinned objects stay where they are and are roots, and the pin count is the number of blocks that hold the cell, so the closure lives as long as any copy Objective-C keeps. extern "objc" methods with a closure parameter make the block, and the trampoline its invoke calls, themselves.

Block<F> is a block Nabi owns, for C functions that take one (dispatch_async); the collector releases it. BlockRef<F> is a block Objective-C passed in, which copy() keeps.

Structs

BlockSource

pub struct Block<F>

A block Nabi owns (one _Block_copy retain, which the collector gives back), calling a closure of type F. Pass it to a C function with as_raw().

  • pub unsafe fn from_raw(b: CPtr<u8>) -> Block<F>§

    Source

    Own heap block b (a +1 one, from _Block_copy or new).

    Safety: b is a heap block calling an F, owned once.

  • pub fn as_raw(self) -> CPtr<u8>§

    Source

    The block, for a C parameter of block type (dispatch_block_t). A callee that keeps it copies it.

  • pub fn new(f: fn() + Send) -> Block<fn()>§

    Source

    A block calling f, on any thread or queue.

  • pub fn new_main_thread(f: fn()) -> Block<fn()>§

    Source

    A block calling f, which need not be Send: it may run only on the main thread (main-queue APIs), and panics anywhere else.

  • pub fn call(self)§

    Source

    Call the closure, as Objective-C would.

Trait implementations 2
  • impl<F> Clone for Block<F>
  • impl<F> Copy for Block<F>

BlockRefSource

pub struct BlockRef<F>

A block Objective-C passed in (a completion handler): valid while the call that passed it runs; copy() keeps it longer.

  • pub unsafe fn from_raw(p: CPtr<u8>) -> BlockRef<F>§

    Source

    The block at p.

    Safety: p is a block calling an F, alive while this is used.

  • pub fn copy(self) -> Block<F>§

    Source

    The block, kept: _Block_copy, released by the collector.

  • pub fn as_raw(self) -> CPtr<u8>§

    Source

    The block, to pass on to a C parameter during the call.

  • pub fn call(self)§

    Source

    Call the block.

Trait implementations 2
  • impl<F> Clone for BlockRef<F>
  • impl<F> Copy for BlockRef<F>

Implementations

impl Descriptor

  • pub fn new(signature: str) -> Descriptor§

    Source

    The descriptor of blocks with type encoding signature ("v@?@"), a string literal.