@@ -50,6 +50,10 @@ impl<'a, T: 'a + RootKind> RootedGuard<'a, T> {
50
50
// SAFETY: self.root points to an inbounds allocation
51
51
unsafe { ( & raw mut ( * self . root ) . ptr ) . cast ( ) }
52
52
}
53
+
54
+ /// Safety: GC must not run during the lifetime of the returned reference.
55
+ pub unsafe fn as_mut < ' b : ' a > ( & mut self ) -> & ' b mut T {
56
+ & mut * ( self . as_ptr ( ) )
53
57
}
54
58
55
59
pub fn get ( & self ) -> T
@@ -70,6 +74,16 @@ impl<'a, T: 'a + RootKind> RootedGuard<'a, T> {
70
74
}
71
75
}
72
76
77
+ impl < ' a , T > RootedGuard < ' a , Option < T > >
78
+ where
79
+ Option < T > : RootKind ,
80
+ {
81
+ pub fn take ( & mut self ) -> Option < T > {
82
+ // Safety: No GC occurs during take call
83
+ unsafe { self . as_mut ( ) . take ( ) }
84
+ }
85
+ }
86
+
73
87
impl < ' a , T : ' a + RootKind > Deref for RootedGuard < ' a , T > {
74
88
type Target = T ;
75
89
fn deref ( & self ) -> & T {
@@ -78,13 +92,6 @@ impl<'a, T: 'a + RootKind> Deref for RootedGuard<'a, T> {
78
92
}
79
93
}
80
94
81
- impl < ' a , T : ' a + RootKind > DerefMut for RootedGuard < ' a , T > {
82
- fn deref_mut ( & mut self ) -> & mut T {
83
- // SAFETY: The rooted value is initialized as long as we exist
84
- unsafe { ( * self . root ) . ptr . assume_init_mut ( ) }
85
- }
86
- }
87
-
88
95
impl < ' a , T : ' a + RootKind > Drop for RootedGuard < ' a , T > {
89
96
fn drop ( & mut self ) {
90
97
// SAFETY: The rooted value is initialized as long as we exist
0 commit comments