]> git.lizzy.rs Git - rust.git/blob - src/doc/unstable-book/src/library-features/fnbox.md
Rollup merge of #61389 - Zoxc:arena-cleanup, r=eddyb
[rust.git] / src / doc / unstable-book / src / library-features / fnbox.md
1 # `fnbox`
2
3 The tracking issue for this feature is [#28796]
4
5 [#28796]: https://github.com/rust-lang/rust/issues/28796
6
7 ------------------------
8
9 This had been a temporary alternative to the following impls:
10
11 ```rust,ignore
12 impl<A, F> FnOnce for Box<F> where F: FnOnce<A> + ?Sized {}
13 impl<A, F> FnMut for Box<F> where F: FnMut<A> + ?Sized {}
14 impl<A, F> Fn for Box<F> where F: Fn<A> + ?Sized {}
15 ```
16
17 The impls are parallel to these (relatively old) impls:
18
19 ```rust,ignore
20 impl<A, F> FnOnce for &mut F where F: FnMut<A> + ?Sized {}
21 impl<A, F> FnMut for &mut F where F: FnMut<A> + ?Sized {}
22 impl<A, F> Fn for &mut F where F: Fn<A> + ?Sized {}
23 impl<A, F> FnOnce for &F where F: Fn<A> + ?Sized {}
24 impl<A, F> FnMut for &F where F: Fn<A> + ?Sized {}
25 impl<A, F> Fn for &F where F: Fn<A> + ?Sized {}
26 ```
27
28 Before the introduction of [`unsized_locals`][unsized_locals], we had been unable to provide the former impls. That means, unlike `&dyn Fn()` or `&mut dyn FnMut()` we could not use `Box<dyn FnOnce()>` at that time.
29
30 [unsized_locals]: ../language-features/unsized-locals.md
31
32 `FnBox()` is an alternative approach to `Box<dyn FnBox()>` is delegated to `FnBox::call_box` which doesn't need unsized locals. As we now have `Box<dyn FnOnce()>` working, the `fnbox` feature is going to be removed.