@@ -236,6 +236,14 @@ impl<'a, T> MutableHandle<'a, T> {
236
236
unsafe { * self . ptr = v }
237
237
}
238
238
239
+ /// Safety: GC must not run during the lifetime of the returned reference.
240
+ pub unsafe fn as_mut < ' b > ( & ' b mut self ) -> & ' b mut T
241
+ where
242
+ ' a : ' b ,
243
+ {
244
+ & mut * ( self . ptr )
245
+ }
246
+
239
247
/// Creates a copy of this object, with a shorter lifetime, that holds a
240
248
/// mutable borrow on the original object. When you write code that wants
241
249
/// to use a `MutableHandle` more than once, you will typically need to
@@ -261,6 +269,13 @@ impl<'a, T> MutableHandle<'a, T> {
261
269
}
262
270
}
263
271
272
+ impl < ' a , T > MutableHandle < ' a , Option < T > > {
273
+ pub fn take ( & mut self ) -> Option < T > {
274
+ // Safety: No GC occurs during take call
275
+ unsafe { self . as_mut ( ) . take ( ) }
276
+ }
277
+ }
278
+
264
279
impl < ' a , T > Deref for MutableHandle < ' a , T > {
265
280
type Target = T ;
266
281
@@ -269,12 +284,6 @@ impl<'a, T> Deref for MutableHandle<'a, T> {
269
284
}
270
285
}
271
286
272
- impl < ' a , T > DerefMut for MutableHandle < ' a , T > {
273
- fn deref_mut ( & mut self ) -> & mut T {
274
- unsafe { & mut * self . ptr }
275
- }
276
- }
277
-
278
287
impl HandleValue < ' static > {
279
288
pub fn null ( ) -> Self {
280
289
unsafe { Self :: from_raw ( RawHandleValue :: null ( ) ) }
0 commit comments