-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 support for FnOnce
to Closure<T>
#1281
Conversation
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.
Looks great to me! I think CI may be failing though?
{ | ||
type FnMut = FnMut($($var),*) -> R; | ||
|
||
fn into_fn_mut(self) -> Box<Self::FnMut> { |
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.
Technically this isn't quite as optimized as we might otherwise want because a FnOnce
that doesn't actually close over anything will allocate because of the discriminant on Option<T>
. I think fully supporting this in the limit though will require specialized support in the JS bindings (the JS bindings are the ones to clear the stored pointer).
Mind throwing a comment somewhere about that? I think this is totally fine as a first pass
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.
(technically the same comment for the one below too)
https://travis-ci.com/rustwasm/wasm-bindgen/jobs/179355779#L951-L961
wat |
We just `no_run` things, but make sure that they still compile.
Sort of. By turning them into
FnMut
and doing a dynamic check that they are only ever called once.I initially tried to get
Closure<FnOnce(...) -> R>
working, but that proved too difficult.