Skip to content

Commit cfda987

Browse files
authored
Merge pull request #27 from rust-scraper/github-actions
Switch to testing on Github Actions
2 parents a1c3a5a + d3c571a commit cfda987

File tree

7 files changed

+204
-91
lines changed

7 files changed

+204
-91
lines changed

.github/workflows/test.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "master"
8+
9+
jobs:
10+
format:
11+
name: Format code
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: dtolnay/rust-toolchain@stable
16+
with:
17+
components: rustfmt
18+
- run: cargo fmt -- --check
19+
20+
clippy:
21+
name: Clippy check
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: dtolnay/rust-toolchain@stable
26+
with:
27+
components: clippy
28+
- uses: Swatinem/rust-cache@v2
29+
- run: cargo clippy --all-targets --all-features -- --deny warnings
30+
31+
test:
32+
name: Test code
33+
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
rust_version: [stable, beta, nightly]
37+
fail-fast: false
38+
steps:
39+
- uses: actions/checkout@v3
40+
- uses: dtolnay/rust-toolchain@master
41+
with:
42+
toolchain: ${{matrix.rust_version}}
43+
- uses: Swatinem/rust-cache@v2
44+
with:
45+
key: ${{matrix.rust_version}}
46+
- run: cargo update
47+
- run: cargo test --all-features

.travis.yml

-8
This file was deleted.

src/iter.rs

+38-22
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,
180+
back: self.back,
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
}

0 commit comments

Comments
 (0)