----- Original Message ----- > From: "Niko Matsakis" <[email protected]> > To: "Brian Anderson" <[email protected]> > Cc: [email protected] > Sent: Friday, December 30, 2011 10:00:16 AM > Subject: Re: [rust-dev] names needed for function types > > 3. `fn[copy]` and `fn[send]`: an alternate version of #2 that I find > more visually appealing. > > Of these, I prefer `fn[copy]` and `fn[send]`. My only reservation is > that the syntax meshes reasonably somewhat awkwardly with capture > clauses in the copy case. A capture clause is used to specify > variables > you wish to copy/move out of the environment; if we moved to > `fn[copy]` > and `fn[send]`, it will also specify the kind restriction. So, you > would write: > > let block_1 = fn(x: T, y: U) -> V { ... }; // currently not > legal > but should be, I think > let boxed_closure_1 = fn[copy](x: T, y: U) -> V { ... }; > let unique_closure_1 = fn[send](x: T, y: U) -> V { ... }; > > and if you wanted to copy the variable `a` out of the environment > explicitly and move the variable `b`, you would write: > > let boxed_closure_2 = fn[copy a; move b](x: T, y: U) -> V { ... > }; > let unique_closure_2 = fn[send; copy a; move b](x: T, y: U) -> V > { > ... }; > > Here you can see that the kind restriction melded with the request to > `copy a`.
How did they 'meld'? Is a copying closure just assumed once you decide to copy or move the upvars? Would 'fn[copy; copy a; move b]' still be allowed? > At the moment, explicit copies are unnecessary anyhow, but > I > personally would like to make them required for mutable local > variables > or for variables whose types are not implicitly copyable (per the no > copies proposal I sent out a while back). > > Thoughts? It's ok. I like it better than anything we've come up with so far. I know there are syntax ambiguities, but it would be more consistent if we could write 'let boxed_closure = fn<copy>(x: T, y: U) ...'. That could then be potentially extended in an obvious way to named functions as well. -Brian _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
