diff options
| author | bors <bors@rust-lang.org> | 2017-02-03 03:23:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-02-03 03:23:35 +0000 |
| commit | 5de2a24b2ebfa42db8eadab911a107b4a67fabdb (patch) | |
| tree | 801d474d204637340ba30ed2521d68f2c9abdf63 /src/libcoretest | |
| parent | 7f294e4c186b461ee8fc28c75d4216822a535d7a (diff) | |
| parent | 8b947a37c8bf396cf80c3790f68253c97d435250 (diff) | |
| download | rust-5de2a24b2ebfa42db8eadab911a107b4a67fabdb.tar.gz rust-5de2a24b2ebfa42db8eadab911a107b4a67fabdb.zip | |
Auto merge of #39287 - wesleywiser:move_cell, r=aturon
Extend Cell to work with non-Copy types I'm not sure that I did this right but all of the tests pass. I also had to move the `new()` function so that `Cell`s with non-`Copy` `T`s could be created. That wasn't in the RFC but I assume it needed to be done?
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/cell.rs | 31 | ||||
| -rw-r--r-- | src/libcoretest/lib.rs | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index 724a312ea79..8585f2f0871 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -210,6 +210,37 @@ fn cell_default() { } #[test] +fn cell_set() { + let cell = Cell::new(10); + cell.set(20); + assert_eq!(20, cell.get()); + + let cell = Cell::new("Hello".to_owned()); + cell.set("World".to_owned()); + assert_eq!("World".to_owned(), cell.into_inner()); +} + +#[test] +fn cell_replace() { + let cell = Cell::new(10); + assert_eq!(10, cell.replace(20)); + assert_eq!(20, cell.get()); + + let cell = Cell::new("Hello".to_owned()); + assert_eq!("Hello".to_owned(), cell.replace("World".to_owned())); + assert_eq!("World".to_owned(), cell.into_inner()); +} + +#[test] +fn cell_into_inner() { + let cell = Cell::new(10); + assert_eq!(10, cell.into_inner()); + + let cell = Cell::new("Hello world".to_owned()); + assert_eq!("Hello world".to_owned(), cell.into_inner()); +} + +#[test] fn refcell_default() { let cell: RefCell<u64> = Default::default(); assert_eq!(0, *cell.borrow()); diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 8e5893b5ecb..87f3afd6889 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -33,6 +33,7 @@ #![feature(unique)] #![feature(ordering_chaining)] #![feature(ptr_unaligned)] +#![feature(move_cell)] extern crate core; extern crate test; |
