Skip to content

Commit caa1ce1

Browse files
committed
cargo fmt
1 parent 1b2e748 commit caa1ce1

File tree

4 files changed

+140
-70
lines changed

4 files changed

+140
-70
lines changed

src/iter.rs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::{slice, vec};
21
use std::ops::Range;
2+
use std::{slice, vec};
33

4-
use {Tree, NodeId, Node, NodeRef};
4+
use {Node, NodeId, NodeRef, Tree};
55

66
/// Iterator that moves out of a tree in insert order.
77
#[derive(Debug)]
88
pub struct IntoIter<T>(vec::IntoIter<Node<T>>);
9-
impl<T> ExactSizeIterator for IntoIter<T> { }
9+
impl<T> ExactSizeIterator for IntoIter<T> {}
1010
impl<T> Iterator for IntoIter<T> {
1111
type Item = T;
1212
fn next(&mut self) -> Option<Self::Item> {
@@ -30,7 +30,7 @@ impl<'a, T: 'a> Clone for Values<'a, T> {
3030
Values(self.0.clone())
3131
}
3232
}
33-
impl<'a, T: 'a> ExactSizeIterator for Values<'a, T> { }
33+
impl<'a, T: 'a> ExactSizeIterator for Values<'a, T> {}
3434
impl<'a, T: 'a> Iterator for Values<'a, T> {
3535
type Item = &'a T;
3636
fn next(&mut self) -> Option<Self::Item> {
@@ -49,7 +49,7 @@ impl<'a, T: 'a> DoubleEndedIterator for Values<'a, T> {
4949
/// Mutable iterator over values in insert order.
5050
#[derive(Debug)]
5151
pub struct ValuesMut<'a, T: 'a>(slice::IterMut<'a, Node<T>>);
52-
impl<'a, T: 'a> ExactSizeIterator for ValuesMut<'a, T> { }
52+
impl<'a, T: 'a> ExactSizeIterator for ValuesMut<'a, T> {}
5353
impl<'a, T: 'a> Iterator for ValuesMut<'a, T> {
5454
type Item = &'a mut T;
5555
fn next(&mut self) -> Option<Self::Item> {
@@ -73,22 +73,29 @@ pub struct Nodes<'a, T: 'a> {
7373
}
7474
impl<'a, T: 'a> Clone for Nodes<'a, T> {
7575
fn clone(&self) -> Self {
76-
Self { tree: self.tree, iter: self.iter.clone() }
76+
Self {
77+
tree: self.tree,
78+
iter: self.iter.clone(),
79+
}
7780
}
7881
}
79-
impl<'a, T: 'a> ExactSizeIterator for Nodes<'a, T> { }
82+
impl<'a, T: 'a> ExactSizeIterator for Nodes<'a, T> {}
8083
impl<'a, T: 'a> Iterator for Nodes<'a, T> {
8184
type Item = NodeRef<'a, T>;
8285
fn next(&mut self) -> Option<Self::Item> {
83-
self.iter.next().map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) })
86+
self.iter
87+
.next()
88+
.map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) })
8489
}
8590
fn size_hint(&self) -> (usize, Option<usize>) {
8691
self.iter.size_hint()
8792
}
8893
}
8994
impl<'a, T: 'a> DoubleEndedIterator for Nodes<'a, T> {
9095
fn next_back(&mut self) -> Option<Self::Item> {
91-
self.iter.next_back().map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) })
96+
self.iter
97+
.next_back()
98+
.map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) })
9299
}
93100
}
94101

@@ -113,7 +120,10 @@ impl<T> Tree<T> {
113120

114121
/// Returns an iterator over nodes in insert order.
115122
pub fn nodes(&self) -> Nodes<T> {
116-
Nodes { tree: self, iter: 0..self.vec.len() }
123+
Nodes {
124+
tree: self,
125+
iter: 0..self.vec.len(),
126+
}
117127
}
118128
}
119129

@@ -165,7 +175,10 @@ pub struct Children<'a, T: 'a> {
165175
}
166176
impl<'a, T: 'a> Clone for Children<'a, T> {
167177
fn clone(&self) -> Self {
168-
Self { front: self.front.clone(), back: self.back.clone() }
178+
Self {
179+
front: self.front.clone(),
180+
back: self.back.clone(),
181+
}
169182
}
170183
}
171184
impl<'a, T: 'a> Iterator for Children<'a, T> {
@@ -204,17 +217,17 @@ pub enum Edge<'a, T: 'a> {
204217
/// Close.
205218
Close(NodeRef<'a, T>),
206219
}
207-
impl<'a, T: 'a> Copy for Edge<'a, T> { }
220+
impl<'a, T: 'a> Copy for Edge<'a, T> {}
208221
impl<'a, T: 'a> Clone for Edge<'a, T> {
209-
fn clone(&self) -> Self { *self }
222+
fn clone(&self) -> Self {
223+
*self
224+
}
210225
}
211-
impl<'a, T: 'a> Eq for Edge<'a, T> { }
226+
impl<'a, T: 'a> Eq for Edge<'a, T> {}
212227
impl<'a, T: 'a> PartialEq for Edge<'a, T> {
213228
fn eq(&self, other: &Self) -> bool {
214229
match (*self, *other) {
215-
(Edge::Open(a), Edge::Open(b)) | (Edge::Close(a), Edge::Close(b)) => {
216-
a == b
217-
},
230+
(Edge::Open(a), Edge::Open(b)) | (Edge::Close(a), Edge::Close(b)) => a == b,
218231
_ => false,
219232
}
220233
}
@@ -228,7 +241,10 @@ pub struct Traverse<'a, T: 'a> {
228241
}
229242
impl<'a, T: 'a> Clone for Traverse<'a, T> {
230243
fn clone(&self) -> Self {
231-
Self { root: self.root, edge: self.edge }
244+
Self {
245+
root: self.root,
246+
edge: self.edge,
247+
}
232248
}
233249
}
234250
impl<'a, T: 'a> Iterator for Traverse<'a, T> {
@@ -237,23 +253,23 @@ impl<'a, T: 'a> Iterator for Traverse<'a, T> {
237253
match self.edge {
238254
None => {
239255
self.edge = Some(Edge::Open(self.root));
240-
},
256+
}
241257
Some(Edge::Open(node)) => {
242258
if let Some(first_child) = node.first_child() {
243259
self.edge = Some(Edge::Open(first_child));
244260
} else {
245261
self.edge = Some(Edge::Close(node));
246262
}
247-
},
263+
}
248264
Some(Edge::Close(node)) => {
249265
if node == self.root {
250-
self.edge = None;
266+
self.edge = None;
251267
} else if let Some(next_sibling) = node.next_sibling() {
252268
self.edge = Some(Edge::Open(next_sibling));
253269
} else {
254270
self.edge = node.parent().map(Edge::Close);
255271
}
256-
},
272+
}
257273
}
258274
self.edge
259275
}

src/lib.rs

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#![warn(
3333
missing_docs,
3434
missing_debug_implementations,
35-
missing_copy_implementations,
35+
missing_copy_implementations
3636
)]
3737

3838
use 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> {}
121121
impl<'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> {}
126128
impl<'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> {
134136
impl<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

Comments
 (0)