-
Notifications
You must be signed in to change notification settings - Fork 22
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
Zero-sized LCellOwner APIs? #39
Comments
so like what if we had |
Those API calls are Or is it a problem with passing the address down the stack to where it is used, through un-inlined calls? |
yeah, it is a bit inconvenient for wrapping LCells in more complex ways. |
Have you tried coding this? I've started coding it up, and there is the problem that when you pass an LCellOwnerRefMut down the stack, we want it to have the normal borrow-handling, i.e. to be "lent" to the method being called, and then to revert ownership to the caller again when the call finishes. So I don't see how I can implement that when the borrow is within the PhantomData. I need to pass it as Let me know if you have any idea how to solve this. |
Or I suppose it could be "single-use", i.e. it gets passed down the stack and then consumed at the leaf. I'll try that. |
so the idea is to have a .borrow_mut() on the LCellOwner that creates an LCellOwnerRefMut, well why not also have a .borrow_mut() the LCellOwnerRefMut? (also .rw/.ro/etc on the LCellOwnerRefMut itself, which also uses autoreborrow by taking &mut/&/etc) |
(fun fact: impl'ing on |
I'm having trouble with this test.
My implementation must be faulty:
Getting a (The nested |
in LCellOwner there is: pub fn rw<'a, T: ?Sized>(&'a mut self, lc: &'a LCell<'id, T>) -> &'a mut T { this "expands" to: pub fn rw<'a, T: ?Sized>(self: &'a mut LCellOwner<'id>, lc: &'a LCell<'id, T>) -> &'a mut T { in the case of the PhantomData, what you have is just we believe it should be |
Okay, that seems to be working. I'll do some more testing in free moments in the coming days to see if I can break it. Also, I would prefer to get my head clear enough on this to understand exactly how this is working. I guess we're entangling the Also, for |
variance is an important concept to keep in mind here. https://doc.rust-lang.org/reference/subtyping.html |
I think it's just lifetime nesting that makes it work, i.e. the existence of The status on this is that I haven't had a lot of time. (My time right now is limited due to some Long Covid symptoms coming and going unfortunately.) Also it adds a lot more API surface, so I have to be careful as I add it to not make a slip. I could implement the existing functionality in terms of these refs internally, but I'd prefer to keep the existing code easy to review without too much abstraction. So the rough plan is to add this with a cargo feature to enable it. I just have to find some clear time to go through all the detail. |
ah, certainly! no worries. take your time! |
I've been looking at implementing reborrowing for a custom type in another situation (for work), and it seems problematic to say the least. Obvious solutions don't work. For future reference: https://haibane-tenshi.github.io/rust-reborrowing/ |
yes, reborrowing is not supported for custom types. the solution is to not use reborrowing for custom types. after all, implicit reborrowing can be made explicit with a simple syntactic choice ( |
It seems that there is one error in that article. He states that reborrowing by making the embedded reference public and then using a macro to reborrow the reference from inside the struct and create a new struct around that reborrowed reference won't work away from the original borrowing site. But I've tried it and it works. So it appears that there is a way around it. So a |
No, a borrow_mut method should be fine, as long as it takes &mut itself. |
This is exactly what I've been failing to achieve. I cannot get a |
what are you trying? |
Okay, that is so weird. I'd deleted the non-working |
Currently, LCellOwner is zero-sized, but &LCellOwner and &mut LCellOwner are not. We wonder if it's possible to have a sound API which borrows the LCellOwner but is zero-sized?
This is a bit of a micro-optimization but anyway.
The text was updated successfully, but these errors were encountered: