@@ -22,19 +22,17 @@ use ty::Unsafe;
22
22
/// A mutable memory location that admits only `Pod` data.
23
23
pub struct Cell < T > {
24
24
priv value : Unsafe < T > ,
25
- priv marker1 : marker:: InvariantType < T > ,
26
- priv marker2 : marker:: NoFreeze ,
27
- priv marker3 : marker:: NoShare ,
25
+ priv marker1 : marker:: NoFreeze ,
26
+ priv marker2 : marker:: NoShare ,
28
27
}
29
28
30
29
impl < T : Pod > Cell < T > {
31
30
/// Creates a new `Cell` containing the given value.
32
31
pub fn new ( value : T ) -> Cell < T > {
33
32
Cell {
34
- value : Unsafe { value : value, marker1 : marker:: InvariantType :: < T > } ,
35
- marker1 : marker:: InvariantType :: < T > ,
36
- marker2 : marker:: NoFreeze ,
37
- marker3 : marker:: NoShare ,
33
+ value : Unsafe :: new ( value) ,
34
+ marker1 : marker:: NoFreeze ,
35
+ marker2 : marker:: NoShare ,
38
36
}
39
37
}
40
38
@@ -75,10 +73,9 @@ impl<T: fmt::Show> fmt::Show for Cell<T> {
75
73
pub struct RefCell < T > {
76
74
priv value : Unsafe < T > ,
77
75
priv borrow : BorrowFlag ,
78
- priv marker1 : marker:: InvariantType < T > ,
79
- priv marker2 : marker:: NoFreeze ,
80
- priv marker3 : marker:: NoPod ,
81
- priv marker4 : marker:: NoShare ,
76
+ priv marker1 : marker:: NoFreeze ,
77
+ priv marker2 : marker:: NoPod ,
78
+ priv marker3 : marker:: NoShare ,
82
79
}
83
80
84
81
// Values [1, MAX-1] represent the number of `Ref` active
@@ -91,11 +88,10 @@ impl<T> RefCell<T> {
91
88
/// Create a new `RefCell` containing `value`
92
89
pub fn new ( value : T ) -> RefCell < T > {
93
90
RefCell {
94
- marker1 : marker:: InvariantType :: < T > ,
95
- marker2 : marker:: NoFreeze ,
96
- marker3 : marker:: NoPod ,
97
- marker4 : marker:: NoShare ,
98
- value : Unsafe { value : value, marker1 : marker:: InvariantType :: < T > } ,
91
+ marker1 : marker:: NoFreeze ,
92
+ marker2 : marker:: NoPod ,
93
+ marker3 : marker:: NoShare ,
94
+ value : Unsafe :: new ( value) ,
99
95
borrow : UNUSED ,
100
96
}
101
97
}
@@ -173,28 +169,6 @@ impl<T> RefCell<T> {
173
169
}
174
170
}
175
171
176
- /// Immutably borrows the wrapped value and applies `blk` to it.
177
- ///
178
- /// # Failure
179
- ///
180
- /// Fails if the value is currently mutably borrowed.
181
- #[ inline]
182
- pub fn with < U > ( & self , blk: |& T | -> U ) -> U {
183
- let ptr = self . borrow ( ) ;
184
- blk ( ptr. get ( ) )
185
- }
186
-
187
- /// Mutably borrows the wrapped value and applies `blk` to it.
188
- ///
189
- /// # Failure
190
- ///
191
- /// Fails if the value is currently borrowed.
192
- #[ inline]
193
- pub fn with_mut < U > ( & self , blk: |& mut T | -> U ) -> U {
194
- let mut ptr = self . borrow_mut ( ) ;
195
- blk ( ptr. get ( ) )
196
- }
197
-
198
172
/// Sets the value, replacing what was there.
199
173
///
200
174
/// # Failure
@@ -372,43 +346,6 @@ mod test {
372
346
assert ! ( x. try_borrow_mut( ) . is_none( ) ) ;
373
347
}
374
348
375
- #[ test]
376
- fn with_ok ( ) {
377
- let x = RefCell :: new ( 0 ) ;
378
- assert_eq ! ( 1 , x. with( |x| * x+1 ) ) ;
379
- }
380
-
381
- #[ test]
382
- #[ should_fail]
383
- fn mut_borrow_with ( ) {
384
- let x = RefCell :: new ( 0 ) ;
385
- let _b1 = x. borrow_mut ( ) ;
386
- x. with ( |x| * x+1 ) ;
387
- }
388
-
389
- #[ test]
390
- fn borrow_with ( ) {
391
- let x = RefCell :: new ( 0 ) ;
392
- let _b1 = x. borrow ( ) ;
393
- assert_eq ! ( 1 , x. with( |x| * x+1 ) ) ;
394
- }
395
-
396
- #[ test]
397
- fn with_mut_ok ( ) {
398
- let x = RefCell :: new ( 0 ) ;
399
- x. with_mut ( |x| * x += 1 ) ;
400
- let b = x. borrow ( ) ;
401
- assert_eq ! ( 1 , * b. get( ) ) ;
402
- }
403
-
404
- #[ test]
405
- #[ should_fail]
406
- fn borrow_with_mut ( ) {
407
- let x = RefCell :: new ( 0 ) ;
408
- let _b = x. borrow ( ) ;
409
- x. with_mut ( |x| * x += 1 ) ;
410
- }
411
-
412
349
#[ test]
413
350
#[ should_fail]
414
351
fn discard_doesnt_unborrow ( ) {
0 commit comments