Skip to content

Switch to testing on Github Actions, reformat and clippy fix #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on:
pull_request:
push:
branches:
- "master"

jobs:
format:
name: Format code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt -- --check

clippy:
name: Clippy check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets --all-features -- --deny warnings

test:
name: Test code
runs-on: ubuntu-latest
strategy:
matrix:
rust_version: [stable, beta, nightly]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust_version}}
- uses: Swatinem/rust-cache@v2
with:
key: ${{matrix.rust_version}}
- run: cargo update
- run: cargo test --all-features
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

60 changes: 38 additions & 22 deletions src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{slice, vec};
use std::ops::Range;
use std::{slice, vec};

use {Tree, NodeId, Node, NodeRef};
use {Node, NodeId, NodeRef, Tree};

/// Iterator that moves out of a tree in insert order.
#[derive(Debug)]
pub struct IntoIter<T>(vec::IntoIter<Node<T>>);
impl<T> ExactSizeIterator for IntoIter<T> { }
impl<T> ExactSizeIterator for IntoIter<T> {}
impl<T> Iterator for IntoIter<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -30,7 +30,7 @@ impl<'a, T: 'a> Clone for Values<'a, T> {
Values(self.0.clone())
}
}
impl<'a, T: 'a> ExactSizeIterator for Values<'a, T> { }
impl<'a, T: 'a> ExactSizeIterator for Values<'a, T> {}
impl<'a, T: 'a> Iterator for Values<'a, T> {
type Item = &'a T;
fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -49,7 +49,7 @@ impl<'a, T: 'a> DoubleEndedIterator for Values<'a, T> {
/// Mutable iterator over values in insert order.
#[derive(Debug)]
pub struct ValuesMut<'a, T: 'a>(slice::IterMut<'a, Node<T>>);
impl<'a, T: 'a> ExactSizeIterator for ValuesMut<'a, T> { }
impl<'a, T: 'a> ExactSizeIterator for ValuesMut<'a, T> {}
impl<'a, T: 'a> Iterator for ValuesMut<'a, T> {
type Item = &'a mut T;
fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -73,22 +73,29 @@ pub struct Nodes<'a, T: 'a> {
}
impl<'a, T: 'a> Clone for Nodes<'a, T> {
fn clone(&self) -> Self {
Self { tree: self.tree, iter: self.iter.clone() }
Self {
tree: self.tree,
iter: self.iter.clone(),
}
}
}
impl<'a, T: 'a> ExactSizeIterator for Nodes<'a, T> { }
impl<'a, T: 'a> ExactSizeIterator for Nodes<'a, T> {}
impl<'a, T: 'a> Iterator for Nodes<'a, T> {
type Item = NodeRef<'a, T>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) })
self.iter
.next()
.map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) })
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl<'a, T: 'a> DoubleEndedIterator for Nodes<'a, T> {
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) })
self.iter
.next_back()
.map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) })
}
}

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

/// Returns an iterator over nodes in insert order.
pub fn nodes(&self) -> Nodes<T> {
Nodes { tree: self, iter: 0..self.vec.len() }
Nodes {
tree: self,
iter: 0..self.vec.len(),
}
}
}

Expand Down Expand Up @@ -165,7 +175,10 @@ pub struct Children<'a, T: 'a> {
}
impl<'a, T: 'a> Clone for Children<'a, T> {
fn clone(&self) -> Self {
Self { front: self.front.clone(), back: self.back.clone() }
Self {
front: self.front,
back: self.back,
}
}
}
impl<'a, T: 'a> Iterator for Children<'a, T> {
Expand Down Expand Up @@ -204,17 +217,17 @@ pub enum Edge<'a, T: 'a> {
/// Close.
Close(NodeRef<'a, T>),
}
impl<'a, T: 'a> Copy for Edge<'a, T> { }
impl<'a, T: 'a> Copy for Edge<'a, T> {}
impl<'a, T: 'a> Clone for Edge<'a, T> {
fn clone(&self) -> Self { *self }
fn clone(&self) -> Self {
*self
}
}
impl<'a, T: 'a> Eq for Edge<'a, T> { }
impl<'a, T: 'a> Eq for Edge<'a, T> {}
impl<'a, T: 'a> PartialEq for Edge<'a, T> {
fn eq(&self, other: &Self) -> bool {
match (*self, *other) {
(Edge::Open(a), Edge::Open(b)) | (Edge::Close(a), Edge::Close(b)) => {
a == b
},
(Edge::Open(a), Edge::Open(b)) | (Edge::Close(a), Edge::Close(b)) => a == b,
_ => false,
}
}
Expand All @@ -228,7 +241,10 @@ pub struct Traverse<'a, T: 'a> {
}
impl<'a, T: 'a> Clone for Traverse<'a, T> {
fn clone(&self) -> Self {
Self { root: self.root, edge: self.edge }
Self {
root: self.root,
edge: self.edge,
}
}
}
impl<'a, T: 'a> Iterator for Traverse<'a, T> {
Expand All @@ -237,23 +253,23 @@ impl<'a, T: 'a> Iterator for Traverse<'a, T> {
match self.edge {
None => {
self.edge = Some(Edge::Open(self.root));
},
}
Some(Edge::Open(node)) => {
if let Some(first_child) = node.first_child() {
self.edge = Some(Edge::Open(first_child));
} else {
self.edge = Some(Edge::Close(node));
}
},
}
Some(Edge::Close(node)) => {
if node == self.root {
self.edge = None;
self.edge = None;
} else if let Some(next_sibling) = node.next_sibling() {
self.edge = Some(Edge::Open(next_sibling));
} else {
self.edge = node.parent().map(Edge::Close);
}
},
}
}
self.edge
}
Expand Down
Loading
Loading