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

Add derivation of Copy trait for each proxy #16

Open
ubnt-intrepid opened this issue Aug 25, 2016 · 8 comments · May be fixed by #37
Open

Add derivation of Copy trait for each proxy #16

ubnt-intrepid opened this issue Aug 25, 2016 · 8 comments · May be fixed by #37

Comments

@ubnt-intrepid
Copy link
Owner

No description provided.

@ubnt-intrepid
Copy link
Owner Author

ubnt-intrepid commented Aug 26, 2016

It is impossible to derive Copy trait for proxy because Rc doesn't have a implementation for Copy (in current implementation).

An alternative is using raw pointer instead of smart pointer. But it is bad situation because it may cause unexpected behaviours related to "unsafe" implementation.

@leoyvens
Copy link
Contributor

leoyvens commented Aug 26, 2016

They need to be Rc because indexes may change. What if the API gave never changing indexes to the variables (which are Copy) and then mapped those to the real indexes (Rc and may change)?

@ubnt-intrepid
Copy link
Owner Author

It sounds a good idea, but their immediate implementation is difficult because the change of internal structure of Model is required.

I'm preparing for next release, so do you mind this matter be a little deferred?

@ubnt-intrepid
Copy link
Owner Author

@ubnt-intrepid ubnt-intrepid removed this from the v0.3.0 milestone Aug 27, 2016
@ubnt-intrepid ubnt-intrepid added this to the v0.4.0 milestone Aug 27, 2016
@leoyvens
Copy link
Contributor

Thanks for taking this into consideration, I don't mind at all, you're doing an amazing work with this lib!

@ubnt-intrepid
Copy link
Owner Author

Another alternative is that all methods of Model make "immutable" (receives &self instead of &mut self). It means that the instance of Model will be treated as an "immutable" object (on the surface). All instances of Proxy can borrow their own indices from the model without violating the Rust's borrowing rule.

@ubnt-intrepid
Copy link
Owner Author

Above scheme is failure because RefCell<T> throws a panic when illegal borrowing is occurred. The avoidance is to use UnsafeCell<T>, but it means that the implementation requires more "unsafe" code.

I think the benefit obtained by implementing Copy trait is less than the implementation cost to avoid Rust's borrowing rule. So I decide not to implement this feature at the present stage.

@ubnt-intrepid
Copy link
Owner Author

I'd misconceptions about the behavior of RefCell ... I'll try again this issue :)

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