Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

Crateblock [][src]

A Rust interface for Objective-C blocks.

For more information on the specifics of the block implementation, seeClang's documentation:http://clang.llvm.org/docs/Block-ABI-Apple.html

Invoking blocks

TheBlock struct is used for invoking blocks from Objective-C. For example,consider this Objective-C function:

int32_t sum(int32_t (^block)(int32_t, int32_t)) {    return block(5, 8);}

We could write it in Rust as the following:

unsafefnsum(block:&Block<(i32,i32),i32>)->i32 {block.call((5,8))}

Note the extra parentheses in thecall method, since the arguments must bepassed as a tuple.

Creating blocks

Creating a block to pass to Objective-C can be done with theConcreteBlockstruct. For example, to create a block that adds twoi32s, we could write:

letblock=ConcreteBlock::new(|a:i32,b:i32|a+b);letblock=block.copy();assert!(unsafe {block.call((5,8)) }==13);

It is important to copy your block to the heap (with thecopy method) beforepassing it to Objective-C; this is because ourConcreteBlock is only meantto be copied once, and we can enforce this in Rust, but if Objective-C codewere to copy it twice we could have a double free.

Structs

Block

An Objective-C block that takes arguments ofA when called andreturns a value ofR.

ConcreteBlock

An Objective-C block whose size is known at compile time and may beconstructed on the stack.

RcBlock

A reference-counted Objective-C block.

Traits

BlockArguments

Types that may be used as the arguments to an Objective-C block.

IntoConcreteBlock

Types that may be converted into aConcreteBlock.

Help

Keyboard Shortcuts

?
Show this help dialog
S
Focus the search field
Move up in search results
Move down in search results
Go to active search result
+
Collapse/expand all sections

Search Tricks

Prefix searches with a type followed by a colon (e.g.fn:) to restrict the search to a given type.

Accepted types are:fn,mod,struct,enum,trait,type,macro, andconst.

Search functions by type signature (e.g.vec -> usize or* -> vec)


[8]
ページ先頭

©2009-2025 Movatter.jp