diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 9d3fa9deed7..24f841acbe9 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -157,6 +157,7 @@ use clone::Clone; use cmp::PartialEq; +use default::Default; use kinds::{marker, Copy}; use ops::{Deref, DerefMut, Drop}; use option::{None, Option, Some}; @@ -211,6 +212,13 @@ impl Clone for Cell { } } +#[unstable] +impl Default for Cell { + fn default() -> Cell { + Cell::new(Default::default()) + } +} + #[unstable = "waiting for `PartialEq` trait to become stable"] impl PartialEq for Cell { fn eq(&self, other: &Cell) -> bool { @@ -337,6 +345,13 @@ impl Clone for RefCell { } } +#[unstable] +impl Default for RefCell { + fn default() -> RefCell { + RefCell::new(Default::default()) + } +} + #[unstable = "waiting for `PartialEq` to become stable"] impl PartialEq for RefCell { fn eq(&self, other: &RefCell) -> bool { diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index 59365045f43..6444cf7ee0e 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -9,6 +9,7 @@ // except according to those terms. use core::cell::*; +use core::default::Default; use std::mem::drop; #[test] @@ -146,3 +147,15 @@ fn as_unsafe_cell() { unsafe { *r2.as_unsafe_cell().get() = 1u; } assert_eq!(1u, *r2.borrow()); } + +#[test] +fn cell_default() { + let cell: Cell = Default::default(); + assert_eq!(0, cell.get()); +} + +#[test] +fn refcell_default() { + let cell: RefCell = Default::default(); + assert_eq!(0, *cell.borrow()); +}