aboutsummaryrefslogtreecommitdiff
path: root/book/src/binding/fn.md
blob: a32ad52a911bcd5f209d5ea7454002e523249d95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{{#title Function pointers — Rust ♡ C++}}
# Function pointers

### Public API:

```cpp,hidelines=...
// rust/cxx.h
...
...namespace rust {

template <typename Signature>
class Fn;

template <typename Ret, typename... Args>
class Fn<Ret(Args...)> final {
public:
  Ret operator()(Args... args) const noexcept;
  Fn operator*() const noexcept;
};
...
...} // namespace rust
```

### Restrictions:

Function pointers with a Result return type are not implemented yet.

Passing a function pointer from C++ to Rust is not implemented yet, only from
Rust to an `extern "C++"` function is implemented.

## Example

Function pointers are commonly useful for implementing [async functions over
FFI](../async.md). See the example code on that page.