diff options
| author | Steven Fackler <sfackler@gmail.com> | 2014-03-20 19:55:52 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2014-03-20 19:55:52 -0700 |
| commit | 181875ca50853418abaa525614252cf46bfce10f (patch) | |
| tree | f8180978f23634cddbd5574ec6058c861d43ff63 /src/libstd | |
| parent | 6eae7df43cd21b76fe91eeaf6ef2af9bd2a8fafc (diff) | |
| download | rust-181875ca50853418abaa525614252cf46bfce10f.tar.gz rust-181875ca50853418abaa525614252cf46bfce10f.zip | |
Remove RefCell::{with, with_mut}
These are superfluous now that we have fixed rvalue lifetimes and Deref.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/cell.rs | 59 | ||||
| -rw-r--r-- | src/libstd/gc.rs | 6 | ||||
| -rw-r--r-- | src/libstd/rc.rs | 6 |
3 files changed, 4 insertions, 67 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index 5733504c0d1..df1c29ded6e 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -173,28 +173,6 @@ impl<T> RefCell<T> { } } - /// Immutably borrows the wrapped value and applies `blk` to it. - /// - /// # Failure - /// - /// Fails if the value is currently mutably borrowed. - #[inline] - pub fn with<U>(&self, blk: |&T| -> U) -> U { - let ptr = self.borrow(); - blk(ptr.get()) - } - - /// Mutably borrows the wrapped value and applies `blk` to it. - /// - /// # Failure - /// - /// Fails if the value is currently borrowed. - #[inline] - pub fn with_mut<U>(&self, blk: |&mut T| -> U) -> U { - let mut ptr = self.borrow_mut(); - blk(ptr.get()) - } - /// Sets the value, replacing what was there. /// /// # Failure @@ -373,43 +351,6 @@ mod test { } #[test] - fn with_ok() { - let x = RefCell::new(0); - assert_eq!(1, x.with(|x| *x+1)); - } - - #[test] - #[should_fail] - fn mut_borrow_with() { - let x = RefCell::new(0); - let _b1 = x.borrow_mut(); - x.with(|x| *x+1); - } - - #[test] - fn borrow_with() { - let x = RefCell::new(0); - let _b1 = x.borrow(); - assert_eq!(1, x.with(|x| *x+1)); - } - - #[test] - fn with_mut_ok() { - let x = RefCell::new(0); - x.with_mut(|x| *x += 1); - let b = x.borrow(); - assert_eq!(1, *b.get()); - } - - #[test] - #[should_fail] - fn borrow_with_mut() { - let x = RefCell::new(0); - let _b = x.borrow(); - x.with_mut(|x| *x += 1); - } - - #[test] #[should_fail] fn discard_doesnt_unborrow() { let x = RefCell::new(0); diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 907a2d21b69..7fb23d77f3c 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -87,10 +87,8 @@ mod tests { fn test_clone() { let x = Gc::new(RefCell::new(5)); let y = x.clone(); - x.borrow().with_mut(|inner| { - *inner = 20; - }); - assert_eq!(y.borrow().with(|x| *x), 20); + *x.borrow().borrow_mut() = 20; + assert_eq!(*y.borrow().borrow(), 20); } #[test] diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index 605cbd3f28a..c41e3b01f47 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -198,10 +198,8 @@ mod tests { fn test_clone() { let x = Rc::new(RefCell::new(5)); let y = x.clone(); - x.deref().with_mut(|inner| { - *inner = 20; - }); - assert_eq!(y.deref().with(|v| *v), 20); + *x.borrow_mut() = 20; + assert_eq!(*y.borrow(), 20); } #[test] |
