]> git.lizzy.rs Git - rust.git/blobdiff - src/doc/unstable-book/src/library-features/fn-traits.md
Rollup merge of #61389 - Zoxc:arena-cleanup, r=eddyb
[rust.git] / src / doc / unstable-book / src / library-features / fn-traits.md
index 3942cda553889a0374d38aafada58cd688e81fe0..29a8aecee6c2fd26e5420a2c06640823e01b99fa 100644 (file)
@@ -1,7 +1,35 @@
 # `fn_traits`
 
-The tracking issue for this feature is: [#29625]
+The tracking issue for this feature is [#29625]
+
+See Also: [`unboxed_closures`](../language-features/unboxed-closures.md)
 
 [#29625]: https://github.com/rust-lang/rust/issues/29625
 
-------------------------
+----
+
+The `fn_traits` feature allows for implementation of the [`Fn*`] traits
+for creating custom closure-like types.
+
+[`Fn*`]: https://doc.rust-lang.org/std/ops/trait.Fn.html
+
+```rust
+#![feature(unboxed_closures)]
+#![feature(fn_traits)]
+
+struct Adder {
+    a: u32
+}
+
+impl FnOnce<(u32, )> for Adder {
+    type Output = u32;
+    extern "rust-call" fn call_once(self, b: (u32, )) -> Self::Output {
+        self.a + b.0
+    }
+}
+
+fn main() {
+    let adder = Adder { a: 3 };
+    assert_eq!(adder(2), 5);
+}
+```