@@ -229,52 +229,6 @@ pub struct Cell<T: ?Sized> {
229
229
value : UnsafeCell < T > ,
230
230
}
231
231
232
- impl < T : Copy > Cell < T > {
233
- /// Returns a copy of the contained value.
234
- ///
235
- /// # Examples
236
- ///
237
- /// ```
238
- /// use std::cell::Cell;
239
- ///
240
- /// let c = Cell::new(5);
241
- ///
242
- /// let five = c.get();
243
- /// ```
244
- #[ inline]
245
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
246
- pub fn get ( & self ) -> T {
247
- unsafe { * self . value . get ( ) }
248
- }
249
-
250
- /// Updates the contained value using a function and returns the new value.
251
- ///
252
- /// # Examples
253
- ///
254
- /// ```
255
- /// #![feature(cell_update)]
256
- ///
257
- /// use std::cell::Cell;
258
- ///
259
- /// let c = Cell::new(5);
260
- /// let new = c.update(|x| x + 1);
261
- ///
262
- /// assert_eq!(new, 6);
263
- /// assert_eq!(c.get(), 6);
264
- /// ```
265
- #[ inline]
266
- #[ unstable( feature = "cell_update" , issue = "50186" ) ]
267
- pub fn update < F > ( & self , f : F ) -> T
268
- where
269
- F : FnOnce ( T ) -> T ,
270
- {
271
- let old = self . get ( ) ;
272
- let new = f ( old) ;
273
- self . set ( new) ;
274
- new
275
- }
276
- }
277
-
278
232
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
279
233
unsafe impl < T : ?Sized > Send for Cell < T > where T : Send { }
280
234
@@ -448,6 +402,52 @@ impl<T> Cell<T> {
448
402
}
449
403
}
450
404
405
+ impl < T : Copy > Cell < T > {
406
+ /// Returns a copy of the contained value.
407
+ ///
408
+ /// # Examples
409
+ ///
410
+ /// ```
411
+ /// use std::cell::Cell;
412
+ ///
413
+ /// let c = Cell::new(5);
414
+ ///
415
+ /// let five = c.get();
416
+ /// ```
417
+ #[ inline]
418
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
419
+ pub fn get ( & self ) -> T {
420
+ unsafe { * self . value . get ( ) }
421
+ }
422
+
423
+ /// Updates the contained value using a function and returns the new value.
424
+ ///
425
+ /// # Examples
426
+ ///
427
+ /// ```
428
+ /// #![feature(cell_update)]
429
+ ///
430
+ /// use std::cell::Cell;
431
+ ///
432
+ /// let c = Cell::new(5);
433
+ /// let new = c.update(|x| x + 1);
434
+ ///
435
+ /// assert_eq!(new, 6);
436
+ /// assert_eq!(c.get(), 6);
437
+ /// ```
438
+ #[ inline]
439
+ #[ unstable( feature = "cell_update" , issue = "50186" ) ]
440
+ pub fn update < F > ( & self , f : F ) -> T
441
+ where
442
+ F : FnOnce ( T ) -> T ,
443
+ {
444
+ let old = self . get ( ) ;
445
+ let new = f ( old) ;
446
+ self . set ( new) ;
447
+ new
448
+ }
449
+ }
450
+
451
451
impl < T : ?Sized > Cell < T > {
452
452
/// Returns a raw pointer to the underlying data in this cell.
453
453
///
0 commit comments