Add VolatileRef::borrow and VolatileRef::borrow_mut#46
Add VolatileRef::borrow and VolatileRef::borrow_mut#46phil-opp merged 1 commit intorust-osdev:mainfrom
VolatileRef::borrow and VolatileRef::borrow_mut#46Conversation
phil-opp
left a comment
There was a problem hiding this comment.
Thanks for the PR! These methods are definitely useful.
Maybe reborrow is a better name? I think the name borrow is associated with creating a & or &mut reference already. Also, there is the core::borrow::Borrow trait that returns a &Borrowed reference too.
Also, could you add a note to the docs that the methods create a VolatileRef with a shorter lifetime? Just to make it clearer how the methods differ from the identity function and why they are useful.
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
I intentionally drew parallels to If you disagree, I can change the name, though. Edit: I think this is similar to how we use
I amended the commit, although I think it can still be improved. I struggle with making this concise but also not too confusing. |
phil-opp
left a comment
There was a problem hiding this comment.
Thanks for the doc updates, looks good!
Good point about the Borrow impl for &T, this is indeed quite similar, given that we're also providing a reference-like type. Let's keep the names then!
These methods are useful when you want to borrow a
VolatileRefbut want to avoid the additional indirection and lifetime of&mut VolatileRef<'a, T>by creating aVolatileRef<'_, T>instead.borrowandborrow_mutmirroras_ptrandas_mut_ptrrespectively, but yield volatile references instead of pointers.