@@ -237,6 +237,17 @@ impl<T:Copy> Cell<T> {
237
237
///
238
238
/// This call borrows `Cell` mutably (at compile-time) which guarantees
239
239
/// that we possess the only reference.
240
+ ///
241
+ /// # Examples
242
+ ///
243
+ /// ```
244
+ /// use std::cell::Cell;
245
+ ///
246
+ /// let mut c = Cell::new(5);
247
+ /// *c.get_mut() += 1;
248
+ ///
249
+ /// assert_eq!(c.get(), 6);
250
+ /// ```
240
251
#[ inline]
241
252
#[ stable( feature = "cell_get_mut" , since = "1.11.0" ) ]
242
253
pub fn get_mut ( & mut self ) -> & mut T {
@@ -388,6 +399,22 @@ impl<T: ?Sized> RefCell<T> {
388
399
///
389
400
/// The returned value can be dispatched on to determine if a call to
390
401
/// `borrow` or `borrow_mut` would succeed.
402
+ ///
403
+ /// # Examples
404
+ ///
405
+ /// ```
406
+ /// #![feature(borrow_state)]
407
+ ///
408
+ /// use std::cell::{BorrowState, RefCell};
409
+ ///
410
+ /// let c = RefCell::new(5);
411
+ ///
412
+ /// match c.borrow_state() {
413
+ /// BorrowState::Writing => println!("Cannot be borrowed"),
414
+ /// BorrowState::Reading => println!("Cannot be borrowed mutably"),
415
+ /// BorrowState::Unused => println!("Can be borrowed (mutably as well)"),
416
+ /// }
417
+ /// ```
391
418
#[ unstable( feature = "borrow_state" , issue = "27733" ) ]
392
419
#[ inline]
393
420
pub fn borrow_state ( & self ) -> BorrowState {
@@ -498,6 +525,17 @@ impl<T: ?Sized> RefCell<T> {
498
525
/// This can be used to circumvent `RefCell`'s safety checks.
499
526
///
500
527
/// This function is `unsafe` because `UnsafeCell`'s field is public.
528
+ ///
529
+ /// # Examples
530
+ ///
531
+ /// ```
532
+ /// #![feature(as_unsafe_cell)]
533
+ ///
534
+ /// use std::cell::RefCell;
535
+ ///
536
+ /// let c = RefCell::new(5);
537
+ /// let c = unsafe { c.as_unsafe_cell() };
538
+ /// ```
501
539
#[ inline]
502
540
#[ unstable( feature = "as_unsafe_cell" , issue = "27708" ) ]
503
541
pub unsafe fn as_unsafe_cell ( & self ) -> & UnsafeCell < T > {
@@ -508,6 +546,17 @@ impl<T: ?Sized> RefCell<T> {
508
546
///
509
547
/// This call borrows `RefCell` mutably (at compile-time) so there is no
510
548
/// need for dynamic checks.
549
+ ///
550
+ /// # Examples
551
+ ///
552
+ /// ```
553
+ /// use std::cell::RefCell;
554
+ ///
555
+ /// let mut c = RefCell::new(5);
556
+ /// *c.get_mut() += 1;
557
+ ///
558
+ /// assert_eq!(c, RefCell::new(6));
559
+ /// ```
511
560
#[ inline]
512
561
#[ stable( feature = "cell_get_mut" , since = "1.11.0" ) ]
513
562
pub fn get_mut ( & mut self ) -> & mut T {
0 commit comments