Skip to content

Commit 8846970

Browse files
committed
Implement Eq for Cell<T>
1 parent 1e6151a commit 8846970

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libstd/cell.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ impl<T:Pod> Clone for Cell<T> {
5555
}
5656
}
5757

58+
impl<T:Eq + Pod> Eq for Cell<T> {
59+
fn eq(&self, other: &Cell<T>) -> bool {
60+
self.get() == other.get()
61+
}
62+
}
63+
5864
/// A mutable memory location with dynamically checked borrow rules
5965
pub struct RefCell<T> {
6066
priv value: T,
@@ -273,11 +279,14 @@ mod test {
273279
#[test]
274280
fn smoketest_cell() {
275281
let x = Cell::new(10);
282+
assert_eq!(x, Cell::new(10));
276283
assert_eq!(x.get(), 10);
277284
x.set(20);
285+
assert_eq!(x, Cell::new(20));
278286
assert_eq!(x.get(), 20);
279287

280288
let y = Cell::new((30, 40));
289+
assert_eq!(y, Cell::new((30, 40)));
281290
assert_eq!(y.get(), (30, 40));
282291
}
283292

0 commit comments

Comments
 (0)