File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 157
157
158
158
use clone:: Clone ;
159
159
use cmp:: PartialEq ;
160
+ use default:: Default ;
160
161
use kinds:: { marker, Copy } ;
161
162
use ops:: { Deref , DerefMut , Drop } ;
162
163
use option:: { None , Option , Some } ;
@@ -213,6 +214,13 @@ impl<T:Copy> Clone for Cell<T> {
213
214
}
214
215
}
215
216
217
+ #[ unstable]
218
+ impl < T : Default + Copy > Default for Cell < T > {
219
+ fn default ( ) -> Cell < T > {
220
+ Cell :: new ( Default :: default ( ) )
221
+ }
222
+ }
223
+
216
224
#[ unstable = "waiting for `PartialEq` trait to become stable" ]
217
225
impl < T : PartialEq + Copy > PartialEq for Cell < T > {
218
226
fn eq ( & self , other : & Cell < T > ) -> bool {
@@ -339,6 +347,13 @@ impl<T: Clone> Clone for RefCell<T> {
339
347
}
340
348
}
341
349
350
+ #[ unstable]
351
+ impl < T : Default > Default for RefCell < T > {
352
+ fn default ( ) -> RefCell < T > {
353
+ RefCell :: new ( Default :: default ( ) )
354
+ }
355
+ }
356
+
342
357
#[ unstable = "waiting for `PartialEq` to become stable" ]
343
358
impl < T : PartialEq > PartialEq for RefCell < T > {
344
359
fn eq ( & self , other : & RefCell < T > ) -> bool {
Original file line number Diff line number Diff line change 9
9
// except according to those terms.
10
10
11
11
use core:: cell:: * ;
12
+ use core:: default:: Default ;
12
13
use std:: mem:: drop;
13
14
14
15
#[ test]
@@ -146,3 +147,15 @@ fn as_unsafe_cell() {
146
147
unsafe { * r2. as_unsafe_cell ( ) . get ( ) = 1 u; }
147
148
assert_eq ! ( 1 u, * r2. borrow( ) ) ;
148
149
}
150
+
151
+ #[ test]
152
+ fn cell_default ( ) {
153
+ let cell: Cell < u32 > = Default :: default ( ) ;
154
+ assert_eq ! ( 0 , cell. get( ) ) ;
155
+ }
156
+
157
+ #[ test]
158
+ fn refcell_default ( ) {
159
+ let cell: RefCell < u64 > = Default :: default ( ) ;
160
+ assert_eq ! ( 0 , * cell. borrow( ) ) ;
161
+ }
You can’t perform that action at this time.
0 commit comments