提交 c46b5b53 编写于 作者: J Jakub Bukaj

rollup merge of #18960: stepancheg/cell-default

......@@ -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 @@ fn clone(&self) -> Cell<T> {
}
}
#[unstable]
impl<T:Default + Copy> Default for Cell<T> {
fn default() -> Cell<T> {
Cell::new(Default::default())
}
}
#[unstable = "waiting for `PartialEq` trait to become stable"]
impl<T:PartialEq + Copy> PartialEq for Cell<T> {
fn eq(&self, other: &Cell<T>) -> bool {
......@@ -337,6 +345,13 @@ fn clone(&self) -> RefCell<T> {
}
}
#[unstable]
impl<T:Default> Default for RefCell<T> {
fn default() -> RefCell<T> {
RefCell::new(Default::default())
}
}
#[unstable = "waiting for `PartialEq` to become stable"]
impl<T: PartialEq> PartialEq for RefCell<T> {
fn eq(&self, other: &RefCell<T>) -> bool {
......
......@@ -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<u32> = Default::default();
assert_eq!(0, cell.get());
}
#[test]
fn refcell_default() {
let cell: RefCell<u64> = Default::default();
assert_eq!(0, *cell.borrow());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册