That would help a bit, but it would still require the programmer to
manually setup and teardown the tuples, pass them to the closure, and so
on. We'll also need to change each and every function that takes an action
parameter to take the extra tuple in every container or container-like
type. And then there's the possibility of modifying variables... It sounds
like a lot of effort working around something the compiler can do
automatically and actually already does automatically; all it needs is the
ability to communicate the programmer intent via the type system so it can
support and enforce it.


On Sat, Nov 30, 2013 at 4:20 PM, Benjamin Herr <[email protected]> wrote:

> On Sat, 2013-11-30 at 09:34 +0200, Oren Ben-Kiki wrote:
>
> > This is a lose-lose situation. If the container takes a `proc`, then
> > Rust complains that it can't capture the non-send-able variable. But
> > if the container takes a stack closure, then Rust complains it can't
> > use the owned variable. Of course, the container will _not_ send the
> > action and will also _not_ call it twice, but it can't express this in
> > the action type :-) The only workaround I found is to use a closure
> > and wrap each and every non-send-able variable in a cell - this is an
> > pointless and downright annoying manual boilerplate code.
>
> I think another previously mentioned workaround is to change all your
> closure-taking functions to have a name ending in "_with" and take an
> extra generic parameter by value that is then passed to the closure. In
> practice, that might end up being a tuple with all the values you're
> need to move into and from within the closure.
>
> It's not ideal and requires cooperation from the API but it probably
> reads better than a bunch of cells. :)
>
> -benh
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to