1
Fork 0

std: Remove the get() method from RefCell wrappers

This method has been entirely obsoleted by autoderef, so there's no reason for
its existence.
This commit is contained in:
Alex Crichton 2014-03-20 15:04:55 -07:00
parent e233a43f5a
commit cd510b3382
3 changed files with 6 additions and 27 deletions

View file

@ -176,8 +176,7 @@ impl<T> RefCell<T> {
/// Fails if the value is currently borrowed. /// Fails if the value is currently borrowed.
#[inline] #[inline]
pub fn set(&self, value: T) { pub fn set(&self, value: T) {
let mut reference = self.borrow_mut(); *self.borrow_mut() = value;
*reference.get() = value;
} }
} }
@ -189,23 +188,19 @@ impl<T:Clone> RefCell<T> {
/// Fails if the value is currently mutably borrowed. /// Fails if the value is currently mutably borrowed.
#[inline] #[inline]
pub fn get(&self) -> T { pub fn get(&self) -> T {
let reference = self.borrow(); (*self.borrow()).clone()
(*reference.get()).clone()
} }
} }
impl<T: Clone> Clone for RefCell<T> { impl<T: Clone> Clone for RefCell<T> {
fn clone(&self) -> RefCell<T> { fn clone(&self) -> RefCell<T> {
let x = self.borrow(); RefCell::new(self.get())
RefCell::new(x.get().clone())
} }
} }
impl<T: Eq> Eq for RefCell<T> { impl<T: Eq> Eq for RefCell<T> {
fn eq(&self, other: &RefCell<T>) -> bool { fn eq(&self, other: &RefCell<T>) -> bool {
let a = self.borrow(); *self.borrow() == *other.borrow()
let b = other.borrow();
a.get() == b.get()
} }
} }
@ -222,14 +217,6 @@ impl<'b, T> Drop for Ref<'b, T> {
} }
} }
impl<'b, T> Ref<'b, T> {
/// Retrieve an immutable reference to the stored value.
#[inline]
pub fn get<'a>(&'a self) -> &'a T {
unsafe{ &*self.parent.value.get() }
}
}
impl<'b, T> Deref<T> for Ref<'b, T> { impl<'b, T> Deref<T> for Ref<'b, T> {
#[inline] #[inline]
fn deref<'a>(&'a self) -> &'a T { fn deref<'a>(&'a self) -> &'a T {
@ -250,14 +237,6 @@ impl<'b, T> Drop for RefMut<'b, T> {
} }
} }
impl<'b, T> RefMut<'b, T> {
/// Retrieve a mutable reference to the stored value.
#[inline]
pub fn get<'a>(&'a mut self) -> &'a mut T {
unsafe{ &mut *self.parent.value.get() }
}
}
impl<'b, T> Deref<T> for RefMut<'b, T> { impl<'b, T> Deref<T> for RefMut<'b, T> {
#[inline] #[inline]
fn deref<'a>(&'a self) -> &'a T { fn deref<'a>(&'a self) -> &'a T {

View file

@ -284,7 +284,7 @@ mod tests {
let a = Rc::new(Cycle { x: RefCell::new(None) }); let a = Rc::new(Cycle { x: RefCell::new(None) });
let b = a.clone().downgrade(); let b = a.clone().downgrade();
*a.deref().x.borrow_mut().get() = Some(b); *a.deref().x.borrow_mut() = Some(b);
// hopefully we don't double-free (or leak)... // hopefully we don't double-free (or leak)...
} }

View file

@ -471,7 +471,7 @@ mod test {
{ {
let mut a = a.borrow_mut(); let mut a = a.borrow_mut();
a.get().next = Some(b); a.next = Some(b);
} }
} }