Skip to content

Commit 00fc090

Browse files
committed
Document the conversion functions and add a into_ptr method
1 parent f220854 commit 00fc090

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/volatile_ref.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,38 @@ impl<'a, T, A> VolatileRef<'a, T, A>
131131
where
132132
T: ?Sized,
133133
{
134-
pub fn as_ptr(&self) -> volatile_ptr::VolatilePtr<'_, T, A::RestrictShared>
134+
/// Borrows this `VolatileRef` as a read-only [`VolatilePtr`].
135+
///
136+
/// Use this method to do (partial) volatile reads of the referenced data.
137+
pub fn as_ptr(&self) -> VolatilePtr<'_, T, A::RestrictShared>
135138
where
136139
A: Access,
137140
{
138-
unsafe { volatile_ptr::VolatilePtr::new_restricted(Default::default(), self.pointer) }
141+
unsafe { VolatilePtr::new_restricted(Default::default(), self.pointer) }
139142
}
140143

141-
pub fn as_mut_ptr(&mut self) -> volatile_ptr::VolatilePtr<'_, T, A>
144+
/// Borrows this `VolatileRef` as a mutable [`VolatilePtr`].
145+
///
146+
/// Use this method to do (partial) volatile reads or writes of the referenced data.
147+
pub fn as_mut_ptr(&mut self) -> VolatilePtr<'_, T, A>
148+
where
149+
A: Access,
150+
{
151+
unsafe { VolatilePtr::new_restricted(Default::default(), self.pointer) }
152+
}
153+
154+
/// Converts this `VolatileRef` into a [`VolatilePtr`] with full access without shortening
155+
/// the lifetime.
156+
///
157+
/// Use this method when you need a [`VolatilePtr`] instance that lives for the full
158+
/// lifetime `'a`.
159+
///
160+
/// This method consumes the `VolatileRef`.
161+
pub fn into_ptr(self) -> VolatilePtr<'a, T, A>
142162
where
143163
A: Access,
144164
{
145-
unsafe { volatile_ptr::VolatilePtr::new_restricted(Default::default(), self.pointer) }
165+
unsafe { VolatilePtr::new_restricted(Default::default(), self.pointer) }
146166
}
147167
}
148168

0 commit comments

Comments
 (0)