@@ -12,10 +12,13 @@ This library provides macros that wrap closures to make them serializable and
12
12
debuggable.
13
13
14
14
``` rust
15
+ use serde_closure :: {traits :: Fn , Fn };
16
+
15
17
let one = 1 ;
16
18
let plus_one = Fn! (| x : i32 | x + one );
17
19
18
- assert_eq! (2 , plus_one (1 ));
20
+ assert_eq! (2 , plus_one . call ((1 ,))); // this works on stable and nightly
21
+ // assert_eq!(2, plus_one(1)); // this only works on nightly
19
22
println! (" {:#?}" , plus_one );
20
23
21
24
// prints:
@@ -25,14 +28,22 @@ println!("{:#?}", plus_one);
25
28
// }
26
29
```
27
30
28
- This library aims to work in as simple and safe a way as possible. It currently
29
- requires nightly Rust for the ` unboxed_closures ` and ` fn_traits ` features (rust
31
+ This library aims to work in as simple and safe a way as possible. On stable
32
+ Rust the wrapped closures implement
33
+ [ ` traits::FnOnce ` ] ( https://docs.rs/serde_closure/0.3/serde_closure/traits/trait.FnOnce.html ) ,
34
+ [ ` traits::FnMut ` ] ( https://docs.rs/serde_closure/0.3/serde_closure/traits/trait.FnMut.html )
35
+ and [ ` traits::Fn ` ] ( https://docs.rs/serde_closure/0.3/serde_closure/traits/trait.Fn.html ) ,
36
+ and when the "nightly" feature is passed
37
+ [ ` std::ops::FnOnce ` ] ( https://doc.rust-lang.org/std/ops/trait.FnOnce.html ) ,
38
+ [ ` std::ops::FnMut ` ] ( https://doc.rust-lang.org/std/ops/trait.FnMut.html ) and
39
+ [ ` std::ops::Fn ` ] ( https://doc.rust-lang.org/std/ops/trait.Fn.html ) are
40
+ implemented as well using the ` unboxed_closures ` and ` fn_traits ` features (rust
30
41
issue [ #29625 ] ( https://github.com/rust-lang/rust/issues/29625 ) ).
31
42
32
43
* There are three macros,
33
- [ ` FnOnce ` ] ( https://docs.rs/serde_closure/0.2 /serde_closure/macro.FnOnce.html ) ,
34
- [ ` FnMut ` ] ( https://docs.rs/serde_closure/0.2 /serde_closure/macro.FnMut.html )
35
- and [ ` Fn ` ] ( https://docs.rs/serde_closure/0.2 /serde_closure/macro.Fn.html ) ,
44
+ [ ` FnOnce ` ] ( https://docs.rs/serde_closure/0.3 /serde_closure/macro.FnOnce.html ) ,
45
+ [ ` FnMut ` ] ( https://docs.rs/serde_closure/0.3 /serde_closure/macro.FnMut.html )
46
+ and [ ` Fn ` ] ( https://docs.rs/serde_closure/0.3 /serde_closure/macro.Fn.html ) ,
36
47
corresponding to the three types of Rust closure.
37
48
* Wrap your closure with one of the macros and it will now implement ` Copy ` ,
38
49
` Clone ` , ` PartialEq ` , ` Eq ` , ` Hash ` , ` PartialOrd ` , ` Ord ` , ` Serialize ` ,
0 commit comments