[rust-dev] &self/&mut self in traits considered harmful(?)

Corey Richardson corey at octayn.net
Thu Jun 12 10:59:22 PDT 2014


Implicit cloning is a non-starter. Clones can be very expensive.
Hiding that cost is undesirable and would require adding Clone to the
language (it's currently a normal library feature).

On Thu, Jun 12, 2014 at 10:46 AM, Tommi <rusty.gates at icloud.com> wrote:
> `Copy` types aren't really relevant to a discussion about adding to Rust the C++ like optimization of moving rvalues (of non-Copy types) when they're passed to certain functions.
>
> On 2014-06-12, at 20:30, Corey Richardson <corey at octayn.net> wrote:
>
>> It's called Copy. `trait Foo: Copy { ... }`.
>>
>> On Thu, Jun 12, 2014 at 10:26 AM, Tommi <rusty.gates at icloud.com> wrote:
>>> I think a new keyword, something like `stable`, is needed for specifying that an argument passed to a trait function is guaranteed to be logically unchanged after the function call. For example:
>>>
>>> trait Foo {
>>>    fn foo(stable self);
>>> }
>>>
>>> impl Foo for int {
>>>    fn foo(&self) {} // OK
>>> }
>>>
>>> impl Foo for uint {
>>>    fn foo(self) {} // OK
>>> }
>>>
>>> impl Foo for Box<int> {
>>>    fn foo(stable self) {} // OK (implicitly clones self)
>>> }
>>>
>>>
>>> fn main() {
>>>    let x: Box<int> = box 42;
>>>    x.foo(); // `x` is implicitly cloned
>>>    x.foo(); // OK
>>> }
>>>
>>> _______________________________________________
>>> Rust-dev mailing list
>>> Rust-dev at mozilla.org
>>> https://mail.mozilla.org/listinfo/rust-dev
>>
>>
>>
>> --
>> http://octayn.net/
>



-- 
http://octayn.net/


More information about the Rust-dev mailing list