Skip to content

Commit 511fdb5

Browse files
committed
Deref instead of methods
1 parent c19baf7 commit 511fdb5

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

text/0000-manually-drop.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,6 @@ impl<T> ManuallyDrop<T> {
7171
}
7272
}
7373

74-
/// Extracts the value from the ManuallyDrop container.
75-
/// Could also be implemented as Deref.
76-
#[unstable(feature = "manually_drop", reason = "recently added", issue = "0")]
77-
pub fn as_ref(&self) -> &T {
78-
unsafe {
79-
&self.value
80-
}
81-
}
82-
83-
/// Extracts the value from the ManuallyDrop container.
84-
/// Could also be implemented as a DerefMut.
85-
#[unstable(feature = "manually_drop", reason = "recently added", issue = "0")]
86-
pub fn as_mut(&mut self) -> &mut T {
87-
unsafe {
88-
&mut self.value
89-
}
90-
}
91-
9274
/// Manually drops the contained value.
9375
///
9476
/// # Unsafety
@@ -97,11 +79,20 @@ impl<T> ManuallyDrop<T> {
9779
/// with the value within invalid. The fact that this function does not consume the wrapper
9880
/// does not statically prevent further reuse.
9981
#[unstable(feature = "manually_drop", reason = "recently added", issue = "0")]
100-
pub unsafe fn manually_drop(&mut self) {
101-
ptr::drop_in_place(&mut self.value)
82+
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {
83+
ptr::drop_in_place(&mut slot.value)
10284
}
10385
}
10486

87+
impl<T> Deref for ManuallyDrop<T> {
88+
type Target = T;
89+
// ...
90+
}
91+
92+
impl<T> DerefMut for ManuallyDrop<T> {
93+
// ...
94+
}
95+
10596
// Other common impls such as `Debug for T: Debug`.
10697
```
10798

@@ -163,4 +154,4 @@ glance;
163154
# Unresolved questions
164155
[unresolved]: #unresolved-questions
165156

166-
* Best way to expose value inside the wrapper.
157+
None known.

0 commit comments

Comments
 (0)