@@ -129,6 +129,15 @@ impl<T> Rawlink<T> {
129
129
}
130
130
}
131
131
132
+ impl < ' a , T > From < & ' a mut Link < T > > for Rawlink < Node < T > > {
133
+ fn from ( node : & ' a mut Link < T > ) -> Self {
134
+ match node. as_mut ( ) {
135
+ None => Rawlink :: none ( ) ,
136
+ Some ( ptr) => Rawlink :: some ( ptr) ,
137
+ }
138
+ }
139
+ }
140
+
132
141
impl < T > Clone for Rawlink < T > {
133
142
#[ inline]
134
143
fn clone ( & self ) -> Rawlink < T > {
@@ -165,8 +174,8 @@ impl<T> LinkedList<T> {
165
174
fn push_front_node ( & mut self , mut new_head : Box < Node < T > > ) {
166
175
match self . list_head {
167
176
None => {
168
- self . list_tail = Rawlink :: some ( & mut * new_head) ;
169
177
self . list_head = link_no_prev ( new_head) ;
178
+ self . list_tail = Rawlink :: from ( & mut self . list_head ) ;
170
179
}
171
180
Some ( ref mut head) => {
172
181
new_head. prev = Rawlink :: none ( ) ;
@@ -197,8 +206,8 @@ impl<T> LinkedList<T> {
197
206
match unsafe { self . list_tail . resolve_mut ( ) } {
198
207
None => return self . push_front_node ( new_tail) ,
199
208
Some ( tail) => {
200
- self . list_tail = Rawlink :: some ( & mut * new_tail) ;
201
209
tail. set_next ( new_tail) ;
210
+ self . list_tail = Rawlink :: from ( & mut tail. next ) ;
202
211
}
203
212
}
204
213
self . length += 1 ;
@@ -297,13 +306,9 @@ impl<T> LinkedList<T> {
297
306
#[ inline]
298
307
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
299
308
pub fn iter_mut ( & mut self ) -> IterMut < T > {
300
- let head_raw = match self . list_head {
301
- Some ( ref mut h) => Rawlink :: some ( & mut * * h) ,
302
- None => Rawlink :: none ( ) ,
303
- } ;
304
- IterMut {
309
+ IterMut {
305
310
nelem : self . len ( ) ,
306
- head : head_raw ,
311
+ head : Rawlink :: from ( & mut self . list_head ) ,
307
312
tail : self . list_tail ,
308
313
list : self
309
314
}
@@ -717,10 +722,7 @@ impl<'a, A> Iterator for IterMut<'a, A> {
717
722
unsafe {
718
723
self . head . resolve_mut ( ) . map ( |next| {
719
724
self . nelem -= 1 ;
720
- self . head = match next. next {
721
- Some ( ref mut node) => Rawlink :: some ( & mut * * node) ,
722
- None => Rawlink :: none ( ) ,
723
- } ;
725
+ self . head = Rawlink :: from ( & mut next. next ) ;
724
726
& mut next. value
725
727
} )
726
728
}
0 commit comments