Add (unstable) FnBox trait as a nicer replacement for Thunk. #23939
Add (unstable) FnBox trait as a nicer replacement for Thunk. #23939alexcrichton merged 3 commits intorust-lang:masterfrom
Thunk. #23939Conversation
|
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
Thunk. Thunk.
|
☔ The latest upstream changes (presumably #23936) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Hmm, encountered an obstacle. Investigating now. |
|
OK, so, there is an obstacle that I'm not sure how best to rectify, though it's also not a strict blocker. Just make the If you have a type like There are two workarounds. You can manually upcast: let x: Box<FnBox<(&mut Foo,), Output=()>> = x;which works because (Interestingly, this would be a kind of use case for variance on traits (that I just opened a PR to remove) except that |
src/libtest/lib.rs
Outdated
There was a problem hiding this comment.
I think this may need to be "FIXME" to get past make tidy
|
Nice! r=me with a few nits I'm ok with having to use unstable syntax to use an unstable feature :) |
1d599ca to
aa4d829
Compare
|
LGTM as well. We can discuss the stabilization story at some point during the beta period. |
comment includes a test that also shows how it can be used.
for `Box<FnBox()>`. I found the alias was still handy because it is shorter than the fully written type. This is a [breaking-change]: convert code using `Invoke` to use `FnBox`, which is usually pretty straight-forward. Code using thunk mostly works if you change `Thunk::new => Box::new` and `foo.invoke(arg)` to `foo(arg)`.
Thunk. Thunk.
|
@bors r=alexcrichton 8eed73f |
Conflicts: src/liballoc/boxed.rs
Add (unstable) FnBox trait as a nicer replacement for
Thunk. The doc comment includes a test that also shows how it can be used.f? @aturon
f? @alexcrichton