Skip to content

Commit d078252

Browse files
committed
unstable book: fn_traits
1 parent 364148d commit d078252

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/doc/unstable-book/src/language-features/optin-builtin-traits.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ has explictly opted out via a _negative impl_.
1515
[`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
1616
[`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
1717

18-
```rust
18+
```rust, ignore
1919
impl !Type for Trait
2020
```
2121

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# `fn_traits`
2+
3+
The tracking issue for this feature is [#29625]
4+
5+
See Also: [`unboxed_closures`](language-features/unboxed_closures.md)
6+
7+
[#29625]: https://github.com/rust-lang/rust/issues/29625
8+
9+
----
10+
11+
The `fn_traits` feature allows for implementation of the [`Fn*`] traits
12+
for creating custom closure-like types.
13+
14+
[`Fn*`]: https://doc.rust-lang.org/std/ops/trait.Fn.html
15+
16+
```rust
17+
#![feature(unboxed_closures)]
18+
#![feature(fn_traits)]
19+
20+
struct Adder {
21+
a: u32
22+
}
23+
24+
impl FnOnce<(u32, )> for Adder {
25+
type Output = u32;
26+
extern "rust-call" fn call_once(self, b: (u32, )) -> Self::Output {
27+
self.a + b.0
28+
}
29+
}
30+
31+
fn main() {
32+
let adder = Adder { a: 3 };
33+
assert_eq!(adder(2), 5);
34+
}
35+
```

0 commit comments

Comments
 (0)