3232#![ warn(
3333 missing_docs,
3434 missing_debug_implementations,
35- missing_copy_implementations,
35+ missing_copy_implementations
3636) ]
3737
3838use std:: fmt:: { self , Debug , Formatter } ;
@@ -117,12 +117,14 @@ pub struct NodeMut<'a, T: 'a> {
117117
118118// Trait implementations regardless of T.
119119
120- impl < ' a , T : ' a > Copy for NodeRef < ' a , T > { }
120+ impl < ' a , T : ' a > Copy for NodeRef < ' a , T > { }
121121impl < ' a , T : ' a > Clone for NodeRef < ' a , T > {
122- fn clone ( & self ) -> Self { * self }
122+ fn clone ( & self ) -> Self {
123+ * self
124+ }
123125}
124126
125- impl < ' a , T : ' a > Eq for NodeRef < ' a , T > { }
127+ impl < ' a , T : ' a > Eq for NodeRef < ' a , T > { }
126128impl < ' a , T : ' a > PartialEq for NodeRef < ' a , T > {
127129 fn eq ( & self , other : & Self ) -> bool {
128130 self . id == other. id
@@ -134,7 +136,9 @@ impl<'a, T: 'a> PartialEq for NodeRef<'a, T> {
134136impl < T > Tree < T > {
135137 /// Creates a tree with a root node.
136138 pub fn new ( root : T ) -> Self {
137- Tree { vec : vec ! [ Node :: new( root) ] }
139+ Tree {
140+ vec : vec ! [ Node :: new( root) ] ,
141+ }
138142 }
139143
140144 /// Creates a tree with a root node and the specified capacity.
@@ -146,7 +150,11 @@ impl<T> Tree<T> {
146150
147151 /// Returns a reference to the specified node.
148152 pub fn get ( & self , id : NodeId ) -> Option < NodeRef < T > > {
149- self . vec . get ( id. to_index ( ) ) . map ( |node| NodeRef { id, node, tree : self } )
153+ self . vec . get ( id. to_index ( ) ) . map ( |node| NodeRef {
154+ id,
155+ node,
156+ tree : self ,
157+ } )
150158 }
151159
152160 /// Returns a mutator of the specified node.
@@ -165,7 +173,11 @@ impl<T> Tree<T> {
165173
166174 /// Returns a reference to the specified node.
167175 pub unsafe fn get_unchecked ( & self , id : NodeId ) -> NodeRef < T > {
168- NodeRef { id, node : self . node ( id) , tree : self }
176+ NodeRef {
177+ id,
178+ node : self . node ( id) ,
179+ tree : self ,
180+ }
169181 }
170182
171183 /// Returns a mutator of the specified node.
@@ -209,27 +221,37 @@ impl<'a, T: 'a> NodeRef<'a, T> {
209221
210222 /// Returns the parent of this node.
211223 pub fn parent ( & self ) -> Option < Self > {
212- self . node . parent . map ( |id| unsafe { self . tree . get_unchecked ( id) } )
224+ self . node
225+ . parent
226+ . map ( |id| unsafe { self . tree . get_unchecked ( id) } )
213227 }
214228
215229 /// Returns the previous sibling of this node.
216230 pub fn prev_sibling ( & self ) -> Option < Self > {
217- self . node . prev_sibling . map ( |id| unsafe { self . tree . get_unchecked ( id) } )
231+ self . node
232+ . prev_sibling
233+ . map ( |id| unsafe { self . tree . get_unchecked ( id) } )
218234 }
219235
220236 /// Returns the next sibling of this node.
221237 pub fn next_sibling ( & self ) -> Option < Self > {
222- self . node . next_sibling . map ( |id| unsafe { self . tree . get_unchecked ( id) } )
238+ self . node
239+ . next_sibling
240+ . map ( |id| unsafe { self . tree . get_unchecked ( id) } )
223241 }
224242
225243 /// Returns the first child of this node.
226244 pub fn first_child ( & self ) -> Option < Self > {
227- self . node . children . map ( |( id, _) | unsafe { self . tree . get_unchecked ( id) } )
245+ self . node
246+ . children
247+ . map ( |( id, _) | unsafe { self . tree . get_unchecked ( id) } )
228248 }
229249
230250 /// Returns the last child of this node.
231251 pub fn last_child ( & self ) -> Option < Self > {
232- self . node . children . map ( |( _, id) | unsafe { self . tree . get_unchecked ( id) } )
252+ self . node
253+ . children
254+ . map ( |( _, id) | unsafe { self . tree . get_unchecked ( id) } )
233255 }
234256
235257 /// Returns true if this node has siblings.
@@ -351,10 +373,14 @@ impl<'a, T: 'a> NodeMut<'a, T> {
351373 }
352374
353375 if let Some ( id) = prev_sibling_id {
354- unsafe { self . tree . node_mut ( id) . next_sibling = next_sibling_id; }
376+ unsafe {
377+ self . tree . node_mut ( id) . next_sibling = next_sibling_id;
378+ }
355379 }
356380 if let Some ( id) = next_sibling_id {
357- unsafe { self . tree . node_mut ( id) . prev_sibling = prev_sibling_id; }
381+ unsafe {
382+ self . tree . node_mut ( id) . prev_sibling = prev_sibling_id;
383+ }
358384 }
359385
360386 let parent = unsafe { self . tree . node_mut ( parent_id) } ;
@@ -383,7 +409,9 @@ impl<'a, T: 'a> NodeMut<'a, T> {
383409 }
384410
385411 if let Some ( id) = last_child_id {
386- unsafe { self . tree . node_mut ( id) . next_sibling = Some ( new_child_id) ; }
412+ unsafe {
413+ self . tree . node_mut ( id) . next_sibling = Some ( new_child_id) ;
414+ }
387415 }
388416
389417 {
@@ -412,7 +440,9 @@ impl<'a, T: 'a> NodeMut<'a, T> {
412440 }
413441
414442 if let Some ( id) = first_child_id {
415- unsafe { self . tree . node_mut ( id) . prev_sibling = Some ( new_child_id) ; }
443+ unsafe {
444+ self . tree . node_mut ( id) . prev_sibling = Some ( new_child_id) ;
445+ }
416446 }
417447
418448 {
@@ -444,7 +474,9 @@ impl<'a, T: 'a> NodeMut<'a, T> {
444474 }
445475
446476 if let Some ( id) = prev_sibling_id {
447- unsafe { self . tree . node_mut ( id) . next_sibling = Some ( new_sibling_id) ; }
477+ unsafe {
478+ self . tree . node_mut ( id) . next_sibling = Some ( new_sibling_id) ;
479+ }
448480 }
449481
450482 self . node ( ) . prev_sibling = Some ( new_sibling_id) ;
@@ -478,7 +510,9 @@ impl<'a, T: 'a> NodeMut<'a, T> {
478510 }
479511
480512 if let Some ( id) = next_sibling_id {
481- unsafe { self . tree . node_mut ( id) . prev_sibling = Some ( new_sibling_id) ; }
513+ unsafe {
514+ self . tree . node_mut ( id) . prev_sibling = Some ( new_sibling_id) ;
515+ }
482516 }
483517
484518 self . node ( ) . next_sibling = Some ( new_sibling_id) ;
@@ -655,21 +689,21 @@ impl<T: Debug> Debug for Tree<T> {
655689 match edge {
656690 Edge :: Open ( node) if node. has_children ( ) => {
657691 write ! ( f, " {:?} => {{" , node. value( ) ) ?;
658- } ,
692+ }
659693 Edge :: Open ( node) if node. next_sibling ( ) . is_some ( ) => {
660694 write ! ( f, " {:?}," , node. value( ) ) ?;
661- } ,
695+ }
662696 Edge :: Open ( node) => {
663697 write ! ( f, " {:?}" , node. value( ) ) ?;
664- } ,
698+ }
665699 Edge :: Close ( node) if node. has_children ( ) => {
666700 if node. next_sibling ( ) . is_some ( ) {
667701 write ! ( f, " }}," ) ?;
668702 } else {
669703 write ! ( f, " }}" ) ?;
670704 }
671- } ,
672- _ => { } ,
705+ }
706+ _ => { }
673707 }
674708 }
675709 write ! ( f, " }}" )
0 commit comments