Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It'd be nice if OwningRefMut could share ownership, but… #34

Open
Rufflewind opened this issue Jun 12, 2017 · 0 comments
Open

It'd be nice if OwningRefMut could share ownership, but… #34

Rufflewind opened this issue Jun 12, 2017 · 0 comments

Comments

@Rufflewind
Copy link

Rufflewind commented Jun 12, 2017

It'd be nice if OwningRefMut could share ownership through Arc, but turns out that doesn't really work because it would cause safety issues due to the presence of .owner() :(

Here's what I wanted to implement for OwningRefMut:

pub fn split<F, U: ?Sized, V: ?Sized>(mut self, f: F) -> (OwningRefMut<O, U>, OwningRefMut<O, V>)
    where F: FnOnce(&mut T) -> (&mut U, &mut V),
          O: stable_deref_trait::CloneStableDeref

But this is not safe, because you could use owner() of OwningRefMut<O, U> to get an immutable reference while holding a mutable reference from the OwningRefMut<O, V>.

This means the API would have to be limited to something like Arc<Erased>, from which you can't take extract any immutable references.

Edit: My current workaround is to wrap the inner object inside an opaque wrapper to prevent the user from acquiring any references from it: Rufflewind@e9ab08f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant