This is assuming that foo and bar are fn(RC<int>), right? In normal use I would expect them to be fn(int) ot fn(&int), unless they need to retain a reference. And in the latter case I would make them fn(&mut RC<int>) and clone() internally.
On Sat, Jun 21, 2014 at 10:52 AM, Igor Bukanov <[email protected]> wrote: > On 21 June 2014 11:10, Nick Cameron <[email protected]> wrote: > > I wonder if we could come up with _some_ > > design that would be better than the current one. > > The reason the ugliness is the repeated clone calls: > > let x = Rc::<int>::new(1); > ... > foo(x.clone()); > bar(x.clone()); > last_x_use(x); > > In this pattern the x is repeatedly cloned to pass it as argument that > will be moved. The ugliness can be eliminated if x as the local > variable can be annotated to tell the compiler to clone it before > passing to functions. I.e. something like: > > let autoclone x = Rc::<int>::new(1); > ... > foo(x); > bar(x); > last_x_use(x); > > Another possibility is to allow for move-in-move-out params that moves > the the value back to the caller when the function returns forcing the > callee to use the clone call if it wants to store the argument for a > later use. > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev >
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
