-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add (unstable) FnBox trait as a nicer replacement for Thunk
.
#23939
Conversation
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 |
@@ -958,7 +959,7 @@ pub fn run_test(opts: &TestOpts, | |||
} | |||
DynMetricFn(f) => { | |||
let mut mm = MetricMap::new(); | |||
f.invoke(&mut mm); | |||
f.call_box((&mut mm,)); // TODO unfortunate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
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