Forgot to send a copy to mailing list.

2014-08-04 10:30 GMT+04:00 Vladimir Matveev <[email protected]>:
> Hi, Paul,
>
> The problem with Clone implementation for mutable reference is not
> that it does not make sense at all; after all, it is just an integer
> value behind the fancy name, and, for example, plain & references [are
> cloneable](http://doc.rust-lang.org/std/clone/trait.Clone.html).
> However, Clone can't be implemented for mutable references because
> &mut is unaliasable - there can't be more than one mutable reference
> pointing to the same thing at the same time, but Clone does exactly
> this.
>
> Moreover, you say that `Pool<T>` is an abstraction over
> `Arc<RWLock<T>>`, right? This means that `T` should also be Share +
> Send, and while references are Share, they are not Send - you can't
> send a reference to another task because it can point to original
> task's stack, and if that original task exits, the reference may
> become invalid. So it is likely that your overall design is incorrect.
> It's hard to say more without more details on what you want to do.
>
> 2014-08-04 6:02 GMT+04:00 Paul Nathan <[email protected]>:
>> Hi,
>>
>> I've gotten myself in a bit of a bind.
>>
>> As part of my work with shared memory with workers, I've implemented a
>> (relatively leaky at the moment) abstraction over Arc<RWLock<T>>, called
>> Pool.
>>
>> Part of my abstraction requires the Clone trait be implemented for T.
>>
>> However, up in the user layer, I have something that looks roughly like this
>>
>> struct Agent { ... }
>>
>> struct Tracker {
>>   Pool<&'r mut Agent>
>> }
>>
>> At which point, the type checker complains and asks me to implement
>> something of this signature:
>>
>> impl<'r> Clone for &'r mut Agent {
>>
>> Which seems quite patently ridiculous - as if I understand things something,
>> I'm being asked to return a reference to something on the *stack* of the fn
>> clone() function. Something smells fishy here...
>>
>> Some assistance and clarification would be appreciated.
>>
>> Regards,
>> Paul
>>
>> _______________________________________________
>> 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

Reply via email to