diff options
| author | Philipp Brüschweiler <blei42@gmail.com> | 2013-06-04 12:03:58 +0200 |
|---|---|---|
| committer | Philipp Brüschweiler <blei42@gmail.com> | 2013-06-04 12:03:58 +0200 |
| commit | 34ee63e93bd763326e676bd634f6f17a8f77791d (patch) | |
| tree | 844bf025d2763daf4913cd7ae965803c20e0e2a3 /src/libstd/cell.rs | |
| parent | 133d45171564c8b7de14523c9f3aa87140b9f043 (diff) | |
std::cell: Modernize constructors
Part of #3853
Diffstat (limited to 'src/libstd/cell.rs')
| -rw-r--r-- | src/libstd/cell.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index ab4752ff847..e1d2b246dd3 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -29,17 +29,17 @@ pub struct Cell<T> { priv value: Option<T> } -/// Creates a new full cell with the given value. -pub fn Cell<T>(value: T) -> Cell<T> { - Cell { value: Some(value) } -} +impl<T> Cell<T> { + /// Creates a new full cell with the given value. + pub fn new(value: T) -> Cell<T> { + Cell { value: Some(value) } + } -/// Creates a new empty cell with no value inside. -pub fn empty_cell<T>() -> Cell<T> { - Cell { value: None } -} + /// Creates a new empty cell with no value inside. + pub fn new_empty() -> Cell<T> { + Cell { value: None } + } -impl<T> Cell<T> { /// Yields the value, failing if the cell is empty. pub fn take(&self) -> T { let this = unsafe { transmute_mut(self) }; @@ -83,7 +83,7 @@ impl<T> Cell<T> { #[test] fn test_basic() { - let value_cell = Cell(~10); + let value_cell = Cell::new(~10); assert!(!value_cell.is_empty()); let value = value_cell.take(); assert!(value == ~10); @@ -96,7 +96,7 @@ fn test_basic() { #[should_fail] #[ignore(cfg(windows))] fn test_take_empty() { - let value_cell = empty_cell::<~int>(); + let value_cell = Cell::new_empty::<~int>(); value_cell.take(); } @@ -104,14 +104,14 @@ fn test_take_empty() { #[should_fail] #[ignore(cfg(windows))] fn test_put_back_non_empty() { - let value_cell = Cell(~10); + let value_cell = Cell::new(~10); value_cell.put_back(~20); } #[test] fn test_with_ref() { let good = 6; - let c = Cell(~[1, 2, 3, 4, 5, 6]); + let c = Cell::new(~[1, 2, 3, 4, 5, 6]); let l = do c.with_ref() |v| { v.len() }; assert_eq!(l, good); } @@ -120,7 +120,7 @@ fn test_with_ref() { fn test_with_mut_ref() { let good = ~[1, 2, 3]; let v = ~[1, 2]; - let c = Cell(v); + let c = Cell::new(v); do c.with_mut_ref() |v| { v.push(3); } let v = c.take(); assert_eq!(v, good); |
