Skip to content

Commit

Permalink
Implement Eq for Cell<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Feb 27, 2014
1 parent 1e6151a commit 8846970
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libstd/cell.rs
Expand Up @@ -55,6 +55,12 @@ impl<T:Pod> Clone for Cell<T> {
}
}

impl<T:Eq + Pod> Eq for Cell<T> {
fn eq(&self, other: &Cell<T>) -> bool {
self.get() == other.get()
}
}

/// A mutable memory location with dynamically checked borrow rules
pub struct RefCell<T> {
priv value: T,
Expand Down Expand Up @@ -273,11 +279,14 @@ mod test {
#[test]
fn smoketest_cell() {
let x = Cell::new(10);
assert_eq!(x, Cell::new(10));
assert_eq!(x.get(), 10);
x.set(20);
assert_eq!(x, Cell::new(20));
assert_eq!(x.get(), 20);

let y = Cell::new((30, 40));
assert_eq!(y, Cell::new((30, 40)));
assert_eq!(y.get(), (30, 40));
}

Expand Down

0 comments on commit 8846970

Please sign in to comment.