Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSome way to simulate `&mut` reborrows in user code #1403
Comments
This comment has been minimized.
This comment has been minimized.
|
In one of the designs for rust-cpython that I explored; I ran into a similar issue: In my case, I ended up going with a different design where the struct could be |
This comment has been minimized.
This comment has been minimized.
|
+1. Commenting to track. |
This comment has been minimized.
This comment has been minimized.
|
We could handle this similarly to unsizing coercions - see So if we generalized, And Should it work on multiple fields, including mixed coercions, e.g. one unsizing and one reborrowing, in different fields? FWIW, we currently kind of support reborrowing combined with unsizing due to the way the |
This comment has been minimized.
This comment has been minimized.
|
@eddyb In my case, my type has multiple fields. If I understand your comment, then implementing |
This comment has been minimized.
This comment has been minimized.
|
@carllerche implementing Personally, I think |
eddyb
referenced this issue
Feb 18, 2016
Open
Tracking issue for DST coercions (coerce_unsized, unsize) stabilization #27732
This comment has been minimized.
This comment has been minimized.
Yes, please. In one piece of code that really should have used |
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
soltanmm
commented
Mar 2, 2016
|
This is sort of possible today. Consider the following (messy, off-the-top-of-my-head, borderline embarrassing) associated-type-encoded-HKTs-based formulation: pub trait Reborrowable<'a> {
type Result;
}
pub trait ReborrowMut<'self_>: for<'a> Reborrowable<'a> + Reborrowable<'self_, Result=Self> {
fn reborrow<'reborrow>(&'reborrow mut self)
-> <Self as Reborrowable<'reborrow>>::Result
where 'self_: 'reborrow;
}This can be used as so: https://gist.github.com/anonymous/4aa1bfddaf5efdb53b15 (sans the type-identity trait bound to ensure I'm not saying that this is a solution - far from it. Still, it's possible to within a single function call on a trait (which is just about what the |
soltanmm
referenced this issue
Apr 30, 2016
Merged
Generic associated types (associated type constructors) #1598
This comment has been minimized.
This comment has been minimized.
dwrensha
commented
Apr 30, 2016
|
This is part of what I was getting at in http://dwrensha.github.io/capnproto-rust/2014/12/27/custom-mutable-references.html |
nrc
added
the
T-lang
label
Aug 19, 2016
This comment has been minimized.
This comment has been minimized.
|
Ran into a need for this today. |
This comment has been minimized.
This comment has been minimized.
|
Edit: better example |
This comment has been minimized.
This comment has been minimized.
|
This would also be super helpful for |
nikomatsakis commentedDec 10, 2015
@carllerche wanted a way to make a newtyped
&mutthat would reborrow in the same implicit way that reborrows do today. That is, with an&mut,foo(ptr)is roughly equivalent tofoo(&mut *ptr), but ifptrisMyRef<'a>(&'a mut ...), then this will not coerce fromMyRef<'a>toMyRef<'b>(where'a:'b).