Skip to content

Commit

Permalink
Add VolatileRef::borrow and VolatileRef::borrow_mut
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Apr 19, 2024
1 parent 2252916 commit 996cab9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Add `VolatileRef::borrow` and `VolatileRef::borrow_mut`

# 0.5.2 – 2024-03-22

- Add implementations for `fmt::Pointer`, `PartialEq`, `Eq`, `PartialOrd`, `Ord` and `Hash`.
Expand Down
20 changes: 20 additions & 0 deletions src/volatile_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ impl<'a, T, A> VolatileRef<'a, T, A>
where
T: ?Sized,
{
/// Immutably borrows from this `VolatileRef`.
///
/// In comparison with creating a `&VolatileRef<'a, T>`, this avoids the additional indirection and lifetime.
pub fn borrow(&self) -> VolatileRef<'_, T, A::RestrictShared>
where
A: Access,
{
unsafe { VolatileRef::new_restricted(Default::default(), self.pointer) }
}

/// Mutably borrows from this `VolatileRef`.
///
/// In comparison with creating a `&mut VolatileRef<'a, T>`, this avoids the additional indirection and lifetime.
pub fn borrow_mut(&mut self) -> VolatileRef<'_, T, A>
where
A: Access,
{
unsafe { VolatileRef::new_restricted(Default::default(), self.pointer) }
}

/// Borrows this `VolatileRef` as a read-only [`VolatilePtr`].
///
/// Use this method to do (partial) volatile reads of the referenced data.
Expand Down

0 comments on commit 996cab9

Please sign in to comment.