File tree 2 files changed +28
-0
lines changed
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 } ;
@@ -211,6 +212,13 @@ impl<T:Copy> Clone for Cell<T> {
211
212
}
212
213
}
213
214
215
+ #[ unstable]
216
+ impl < T : Default + Copy > Default for Cell < T > {
217
+ fn default ( ) -> Cell < T > {
218
+ Cell :: new ( Default :: default ( ) )
219
+ }
220
+ }
221
+
214
222
#[ unstable = "waiting for `PartialEq` trait to become stable" ]
215
223
impl < T : PartialEq + Copy > PartialEq for Cell < T > {
216
224
fn eq ( & self , other : & Cell < T > ) -> bool {
@@ -337,6 +345,13 @@ impl<T: Clone> Clone for RefCell<T> {
337
345
}
338
346
}
339
347
348
+ #[ unstable]
349
+ impl < T : Default > Default for RefCell < T > {
350
+ fn default ( ) -> RefCell < T > {
351
+ RefCell :: new ( Default :: default ( ) )
352
+ }
353
+ }
354
+
340
355
#[ unstable = "waiting for `PartialEq` to become stable" ]
341
356
impl < T : PartialEq > PartialEq for RefCell < T > {
342
357
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