@@ -20,13 +20,13 @@ mutation when the data structure should be immutable.
20
20
*/
21
21
22
22
use util:: with;
23
- use cast:: transmute_immut;
23
+ use cast:: { transmute_mut , transmute_immut} ;
24
24
25
25
enum Mode { ReadOnly , Mutable , Immutable }
26
26
27
27
struct Data < T > {
28
- priv mut value : T ,
29
- priv mut mode : Mode
28
+ priv value : T ,
29
+ priv mode : Mode
30
30
}
31
31
32
32
pub type Mut < T > = Data < T > ;
@@ -50,23 +50,19 @@ pub impl<T> Data<T> {
50
50
ReadOnly | Mutable => {}
51
51
}
52
52
53
- do with(&mut self.mode, Mutable) {
54
- op(&mut self.value)
53
+ do with( unsafe { transmute_mut(& self.mode) } , Mutable) {
54
+ op( unsafe { transmute_mut(& self.value) } )
55
55
}
56
56
}
57
57
58
- fn borrow_const<R>(&self, op: &fn(t: &const T) -> R) -> R {
59
- op(&const self.value)
60
- }
61
-
62
58
fn borrow_imm<R>(&self, op: &fn(t: &T) -> R) -> R {
63
59
match self.mode {
64
60
Mutable => fail!(~" currently mutable" ) ,
65
61
ReadOnly | Immutable => { }
66
62
}
67
63
68
- do with( & mut self . mode , Immutable ) {
69
- op ( unsafe { transmute_immut ( & mut self . value ) } )
64
+ do with( unsafe { transmute_mut ( & self . mode ) } , Immutable ) {
65
+ op ( & self . value )
70
66
}
71
67
}
72
68
@@ -97,62 +93,3 @@ pub fn test_imm_in_mut() {
97
93
}
98
94
}
99
95
}
100
-
101
- #[ test]
102
- pub fn test_const_in_mut ( ) {
103
- let m = @Mut ( 1 ) ;
104
- do m. borrow_mut |p| {
105
- do m. borrow_const |q| {
106
- assert ! ( * p == * q) ;
107
- * p += 1 ;
108
- assert ! ( * p == * q) ;
109
- }
110
- }
111
- }
112
-
113
- #[ test]
114
- pub fn test_mut_in_const ( ) {
115
- let m = @Mut ( 1 ) ;
116
- do m. borrow_const |p| {
117
- do m. borrow_mut |q| {
118
- assert ! ( * p == * q) ;
119
- * q += 1 ;
120
- assert ! ( * p == * q) ;
121
- }
122
- }
123
- }
124
-
125
- #[ test]
126
- pub fn test_imm_in_const ( ) {
127
- let m = @Mut ( 1 ) ;
128
- do m. borrow_const |p| {
129
- do m. borrow_imm |q| {
130
- assert ! ( * p == * q) ;
131
- }
132
- }
133
- }
134
-
135
- #[ test]
136
- pub fn test_const_in_imm ( ) {
137
- let m = @Mut ( 1 ) ;
138
- do m. borrow_imm |p| {
139
- do m. borrow_const |q| {
140
- assert ! ( * p == * q) ;
141
- }
142
- }
143
- }
144
-
145
-
146
- #[ test]
147
- #[ ignore( cfg( windows) ) ]
148
- #[ should_fail]
149
- pub fn test_mut_in_imm_in_const ( ) {
150
- let m = @Mut ( 1 ) ;
151
- do m. borrow_const |_p| {
152
- do m. borrow_imm |_q| {
153
- do m. borrow_mut |_r| {
154
- }
155
- }
156
- }
157
- }
158
-
0 commit comments