ego-tree-0.6.2/.gitignore010064400007650000024000000000221326672160700134410ustar0000000000000000target Cargo.lock ego-tree-0.6.2/.travis.yml010064400007650000024000000001431326672160700135660ustar0000000000000000language: rust rust: - stable - beta - nightly matrix: allow_failures: - rust: nightly ego-tree-0.6.2/Cargo.toml.orig010064400007650000024000000004121354520607200143350ustar0000000000000000[package] name = "ego-tree" version = "0.6.2" description = "Vec-backed ID-tree" keywords = ["tree", "vec", "id", "index"] authors = ["Curtis McEnroe "] license = "ISC" repository = "https://github.com/programble/ego-tree" readme = "README.md" ego-tree-0.6.2/Cargo.toml0000644000000014270000000000000106110ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "ego-tree" version = "0.6.2" authors = ["Curtis McEnroe "] description = "Vec-backed ID-tree" readme = "README.md" keywords = ["tree", "vec", "id", "index"] license = "ISC" repository = "https://github.com/programble/ego-tree" ego-tree-0.6.2/LICENSE010064400007650000024000000013611326672160700124650ustar0000000000000000Copyright © 2016, Curtis McEnroe Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ego-tree-0.6.2/README.md010064400007650000024000000005221326672160700127350ustar0000000000000000# Ego Tree [![Crate version][crate-badge]][crate] [![Build status][travis-badge]][travis] [crate]: https://crates.io/crates/ego-tree [travis]: https://travis-ci.org/programble/ego-tree [crate-badge]: https://img.shields.io/crates/v/ego-tree.svg [travis-badge]: https://img.shields.io/travis/programble/ego-tree.svg Vec-backed ID-tree. ego-tree-0.6.2/src/iter.rs010064400007650000024000000222731354520563600135640ustar0000000000000000use std::{slice, vec}; use std::ops::Range; use {Tree, NodeId, Node, NodeRef}; /// Iterator that moves out of a tree in insert order. #[derive(Debug)] pub struct IntoIter(vec::IntoIter>); impl ExactSizeIterator for IntoIter { } impl Iterator for IntoIter { type Item = T; fn next(&mut self) -> Option { self.0.next().map(|node| node.value) } fn size_hint(&self) -> (usize, Option) { self.0.size_hint() } } impl DoubleEndedIterator for IntoIter { fn next_back(&mut self) -> Option { self.0.next_back().map(|node| node.value) } } /// Iterator over values in insert order. #[derive(Debug)] pub struct Values<'a, T: 'a>(slice::Iter<'a, Node>); impl<'a, T: 'a> Clone for Values<'a, T> { fn clone(&self) -> Self { Values(self.0.clone()) } } 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.0.next().map(|node| &node.value) } fn size_hint(&self) -> (usize, Option) { self.0.size_hint() } } impl<'a, T: 'a> DoubleEndedIterator for Values<'a, T> { fn next_back(&mut self) -> Option { self.0.next_back().map(|node| &node.value) } } /// Mutable iterator over values in insert order. #[derive(Debug)] pub struct ValuesMut<'a, T: 'a>(slice::IterMut<'a, Node>); 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.0.next().map(|node| &mut node.value) } fn size_hint(&self) -> (usize, Option) { self.0.size_hint() } } impl<'a, T: 'a> DoubleEndedIterator for ValuesMut<'a, T> { fn next_back(&mut self) -> Option { self.0.next_back().map(|node| &mut node.value) } } /// Iterator over nodes in insert order. #[derive(Debug)] pub struct Nodes<'a, T: 'a> { tree: &'a Tree, iter: Range, } impl<'a, T: 'a> Clone for Nodes<'a, T> { fn clone(&self) -> Self { Self { tree: self.tree, iter: self.iter.clone() } } } 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.iter.next().map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) }) } fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } impl<'a, T: 'a> DoubleEndedIterator for Nodes<'a, T> { fn next_back(&mut self) -> Option { self.iter.next_back().map(|i| unsafe { self.tree.get_unchecked(NodeId::from_index(i)) }) } } impl IntoIterator for Tree { type Item = T; type IntoIter = IntoIter; fn into_iter(self) -> Self::IntoIter { IntoIter(self.vec.into_iter()) } } impl Tree { /// Returns an iterator over values in insert order. pub fn values(&self) -> Values { Values(self.vec.iter()) } /// Returns a mutable iterator over values in insert order. pub fn values_mut(&mut self) -> ValuesMut { ValuesMut(self.vec.iter_mut()) } /// Returns an iterator over nodes in insert order. pub fn nodes(&self) -> Nodes { Nodes { tree: self, iter: 0..self.vec.len() } } } macro_rules! axis_iterators { ($(#[$m:meta] $i:ident($f:path);)*) => { $( #[$m] #[derive(Debug)] pub struct $i<'a, T: 'a>(Option>); impl<'a, T: 'a> Clone for $i<'a, T> { fn clone(&self) -> Self { $i(self.0) } } impl<'a, T: 'a> Iterator for $i<'a, T> { type Item = NodeRef<'a, T>; fn next(&mut self) -> Option { let node = self.0.take(); self.0 = node.as_ref().and_then($f); node } } )* }; } axis_iterators! { /// Iterator over ancestors. Ancestors(NodeRef::parent); /// Iterator over previous siblings. PrevSiblings(NodeRef::prev_sibling); /// Iterator over next siblings. NextSiblings(NodeRef::next_sibling); /// Iterator over first children. FirstChildren(NodeRef::first_child); /// Iterator over last children. LastChildren(NodeRef::last_child); } /// Iterator over children. #[derive(Debug)] pub struct Children<'a, T: 'a> { front: Option>, back: Option>, } impl<'a, T: 'a> Clone for Children<'a, T> { fn clone(&self) -> Self { Self { front: self.front.clone(), back: self.back.clone() } } } impl<'a, T: 'a> Iterator for Children<'a, T> { type Item = NodeRef<'a, T>; fn next(&mut self) -> Option { if self.front == self.back { let node = self.front.take(); self.back = None; node } else { let node = self.front.take(); self.front = node.as_ref().and_then(NodeRef::next_sibling); node } } } impl<'a, T: 'a> DoubleEndedIterator for Children<'a, T> { fn next_back(&mut self) -> Option { if self.back == self.front { let node = self.back.take(); self.front = None; node } else { let node = self.back.take(); self.back = node.as_ref().and_then(NodeRef::prev_sibling); node } } } /// Open or close edge of a node. #[derive(Debug)] pub enum Edge<'a, T: 'a> { /// Open. Open(NodeRef<'a, T>), /// Close. Close(NodeRef<'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 } } 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 }, _ => false, } } } /// Iterator which traverses a subtree. #[derive(Debug)] pub struct Traverse<'a, T: 'a> { root: NodeRef<'a, T>, edge: Option>, } impl<'a, T: 'a> Clone for Traverse<'a, T> { fn clone(&self) -> Self { Self { root: self.root, edge: self.edge } } } impl<'a, T: 'a> Iterator for Traverse<'a, T> { type Item = Edge<'a, T>; fn next(&mut self) -> Option { 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; } 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 } } /// Iterator over a node and its descendants. #[derive(Debug)] pub struct Descendants<'a, T: 'a>(Traverse<'a, T>); impl<'a, T: 'a> Clone for Descendants<'a, T> { fn clone(&self) -> Self { Descendants(self.0.clone()) } } impl<'a, T: 'a> Iterator for Descendants<'a, T> { type Item = NodeRef<'a, T>; fn next(&mut self) -> Option { for edge in &mut self.0 { if let Edge::Open(node) = edge { return Some(node); } } None } } impl<'a, T: 'a> NodeRef<'a, T> { /// Returns an iterator over ancestors. pub fn ancestors(&self) -> Ancestors<'a, T> { Ancestors(self.parent()) } /// Returns an iterator over previous siblings. pub fn prev_siblings(&self) -> PrevSiblings<'a, T> { PrevSiblings(self.prev_sibling()) } /// Returns an iterator over next siblings. pub fn next_siblings(&self) -> NextSiblings<'a, T> { NextSiblings(self.next_sibling()) } /// Returns an iterator over first children. pub fn first_children(&self) -> FirstChildren<'a, T> { FirstChildren(self.first_child()) } /// Returns an iterator over last children. pub fn last_children(&self) -> LastChildren<'a, T> { LastChildren(self.last_child()) } /// Returns an iterator over children. pub fn children(&self) -> Children<'a, T> { Children { front: self.first_child(), back: self.last_child(), } } /// Returns an iterator which traverses the subtree starting at this node. pub fn traverse(&self) -> Traverse<'a, T> { Traverse { root: *self, edge: None, } } /// Returns an iterator over this node and its descendants. pub fn descendants(&self) -> Descendants<'a, T> { Descendants(self.traverse()) } } ego-tree-0.6.2/src/lib.rs010064400007650000024000000473111354520563600133670ustar0000000000000000//! Vec-backed ID-tree. //! //! # Behavior //! //! - Trees have at least a root node; //! - Nodes have zero or more ordered children; //! - Nodes have at most one parent; //! - Nodes can be detached (orphaned) but not removed; //! - Node parent, next sibling, previous sibling, first child and last child //! can be accessed in constant time; //! - All methods perform in constant time; //! - All iterators perform in linear time. //! //! # Examples //! //! ``` //! let mut tree = ego_tree::Tree::new('a'); //! let mut root = tree.root_mut(); //! root.append('b'); //! let mut c = root.append('c'); //! c.append('d'); //! c.append('e'); //! ``` //! //! ``` //! #[macro_use] extern crate ego_tree; //! # fn main() { //! let tree = tree!('a' => { 'b', 'c' => { 'd', 'e' } }); //! # } //! ``` #![warn( missing_docs, missing_debug_implementations, missing_copy_implementations, )] use std::fmt::{self, Debug, Formatter}; use std::num::NonZeroUsize; /// Vec-backed ID-tree. /// /// Always contains at least a root node. #[derive(Clone, PartialEq, Eq, Hash)] pub struct Tree { vec: Vec>, } /// Node ID. /// /// Index into a `Tree`-internal `Vec`. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct NodeId(NonZeroUsize); impl NodeId { // Safety: `n` must not equal `usize::MAX`. // (This is never the case for `Vec::len()`, that would mean it owns // the entire address space without leaving space for even the its pointer.) unsafe fn from_index(n: usize) -> Self { NodeId(NonZeroUsize::new_unchecked(n + 1)) } fn to_index(self) -> usize { self.0.get() - 1 } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] struct Node { parent: Option, prev_sibling: Option, next_sibling: Option, children: Option<(NodeId, NodeId)>, value: T, } fn _static_assert_size_of_node() { // "Instanciating" the generic `transmute` function without calling it // still triggers the magic compile-time check // that input and output types have the same `size_of()`. let _ = std::mem::transmute::, [usize; 5]>; } impl Node { fn new(value: T) -> Self { Node { parent: None, prev_sibling: None, next_sibling: None, children: None, value, } } } /// Node reference. #[derive(Debug)] pub struct NodeRef<'a, T: 'a> { /// Node ID. id: NodeId, /// Tree containing the node. tree: &'a Tree, node: &'a Node, } /// Node mutator. #[derive(Debug)] pub struct NodeMut<'a, T: 'a> { /// Node ID. id: NodeId, /// Tree containing the node. tree: &'a mut Tree, } // Trait implementations regardless of T. impl<'a, T: 'a> Copy for NodeRef<'a, T> { } impl<'a, T: 'a> Clone for NodeRef<'a, T> { fn clone(&self) -> Self { *self } } impl<'a, T: 'a> Eq for NodeRef<'a, T> { } impl<'a, T: 'a> PartialEq for NodeRef<'a, T> { fn eq(&self, other: &Self) -> bool { self.id == other.id && self.tree as *const _ == other.tree as *const _ && self.node as *const _ == other.node as *const _ } } impl Tree { /// Creates a tree with a root node. pub fn new(root: T) -> Self { Tree { vec: vec![Node::new(root)] } } /// Creates a tree with a root node and the specified capacity. pub fn with_capacity(root: T, capacity: usize) -> Self { let mut vec = Vec::with_capacity(capacity); vec.push(Node::new(root)); Tree { vec } } /// Returns a reference to the specified node. pub fn get(&self, id: NodeId) -> Option> { self.vec.get(id.to_index()).map(|node| NodeRef { id, node, tree: self }) } /// Returns a mutator of the specified node. pub fn get_mut(&mut self, id: NodeId) -> Option> { let exists = self.vec.get(id.to_index()).map(|_| ()); exists.map(move |_| NodeMut { id, tree: self }) } unsafe fn node(&self, id: NodeId) -> &Node { self.vec.get_unchecked(id.to_index()) } unsafe fn node_mut(&mut self, id: NodeId) -> &mut Node { self.vec.get_unchecked_mut(id.to_index()) } /// Returns a reference to the specified node. pub unsafe fn get_unchecked(&self, id: NodeId) -> NodeRef { NodeRef { id, node: self.node(id), tree: self } } /// Returns a mutator of the specified node. pub unsafe fn get_unchecked_mut(&mut self, id: NodeId) -> NodeMut { NodeMut { id, tree: self } } /// Returns a reference to the root node. pub fn root(&self) -> NodeRef { unsafe { self.get_unchecked(NodeId::from_index(0)) } } /// Returns a mutator of the root node. pub fn root_mut(&mut self) -> NodeMut { unsafe { self.get_unchecked_mut(NodeId::from_index(0)) } } /// Creates an orphan node. pub fn orphan(&mut self, value: T) -> NodeMut { let id = unsafe { NodeId::from_index(self.vec.len()) }; self.vec.push(Node::new(value)); unsafe { self.get_unchecked_mut(id) } } } impl<'a, T: 'a> NodeRef<'a, T> { /// Returns the ID of this node. pub fn id(&self) -> NodeId { self.id } /// Returns the tree owning this node. pub fn tree(&self) -> &'a Tree { self.tree } /// Returns the value of this node. pub fn value(&self) -> &'a T { &self.node.value } /// Returns the parent of this node. pub fn parent(&self) -> Option { self.node.parent.map(|id| unsafe { self.tree.get_unchecked(id) }) } /// Returns the previous sibling of this node. pub fn prev_sibling(&self) -> Option { self.node.prev_sibling.map(|id| unsafe { self.tree.get_unchecked(id) }) } /// Returns the next sibling of this node. pub fn next_sibling(&self) -> Option { self.node.next_sibling.map(|id| unsafe { self.tree.get_unchecked(id) }) } /// Returns the first child of this node. pub fn first_child(&self) -> Option { self.node.children.map(|(id, _)| unsafe { self.tree.get_unchecked(id) }) } /// Returns the last child of this node. pub fn last_child(&self) -> Option { self.node.children.map(|(_, id)| unsafe { self.tree.get_unchecked(id) }) } /// Returns true if this node has siblings. pub fn has_siblings(&self) -> bool { self.node.prev_sibling.is_some() || self.node.next_sibling.is_some() } /// Returns true if this node has children. pub fn has_children(&self) -> bool { self.node.children.is_some() } } impl<'a, T: 'a> NodeMut<'a, T> { /// Returns the ID of this node. pub fn id(&self) -> NodeId { self.id } /// Returns the tree owning this node. pub fn tree(&mut self) -> &mut Tree { self.tree } fn node(&mut self) -> &mut Node { unsafe { self.tree.node_mut(self.id) } } /// Returns the value of this node. pub fn value(&mut self) -> &mut T { &mut self.node().value } /// Returns the parent of this node. pub fn parent(&mut self) -> Option> { let id = self.node().parent; id.map(move |id| unsafe { self.tree.get_unchecked_mut(id) }) } /// Returns the previous sibling of this node. pub fn prev_sibling(&mut self) -> Option> { let id = self.node().prev_sibling; id.map(move |id| unsafe { self.tree.get_unchecked_mut(id) }) } /// Returns the next sibling of this node. pub fn next_sibling(&mut self) -> Option> { let id = self.node().next_sibling; id.map(move |id| unsafe { self.tree.get_unchecked_mut(id) }) } /// Returns the first child of this node. pub fn first_child(&mut self) -> Option> { let ids = self.node().children; ids.map(move |(id, _)| unsafe { self.tree.get_unchecked_mut(id) }) } /// Returns the last child of this node. pub fn last_child(&mut self) -> Option> { let ids = self.node().children; ids.map(move |(_, id)| unsafe { self.tree.get_unchecked_mut(id) }) } /// Returns true if this node has siblings. pub fn has_siblings(&self) -> bool { unsafe { self.tree.get_unchecked(self.id).has_siblings() } } /// Returns true if this node has children. pub fn has_children(&self) -> bool { unsafe { self.tree.get_unchecked(self.id).has_children() } } /// Appends a new child to this node. pub fn append(&mut self, value: T) -> NodeMut { let id = self.tree.orphan(value).id; self.append_id(id) } /// Prepends a new child to this node. pub fn prepend(&mut self, value: T) -> NodeMut { let id = self.tree.orphan(value).id; self.prepend_id(id) } /// Inserts a new sibling before this node. /// /// # Panics /// /// Panics if this node is an orphan. pub fn insert_before(&mut self, value: T) -> NodeMut { let id = self.tree.orphan(value).id; self.insert_id_before(id) } /// Inserts a new sibling after this node. /// /// # Panics /// /// Panics if this node is an orphan. pub fn insert_after(&mut self, value: T) -> NodeMut { let id = self.tree.orphan(value).id; self.insert_id_after(id) } /// Detaches this node from its parent. pub fn detach(&mut self) { let parent_id = match self.node().parent { Some(id) => id, None => return, }; let prev_sibling_id = self.node().prev_sibling; let next_sibling_id = self.node().next_sibling; { self.node().parent = None; self.node().prev_sibling = None; self.node().next_sibling = None; } if let Some(id) = prev_sibling_id { unsafe { self.tree.node_mut(id).next_sibling = next_sibling_id; } } if let Some(id) = next_sibling_id { unsafe { self.tree.node_mut(id).prev_sibling = prev_sibling_id; } } let parent = unsafe { self.tree.node_mut(parent_id) }; let (first_child_id, last_child_id) = parent.children.unwrap(); if first_child_id == last_child_id { parent.children = None; } else if first_child_id == self.id { parent.children = Some((next_sibling_id.unwrap(), last_child_id)); } else if last_child_id == self.id { parent.children = Some((first_child_id, prev_sibling_id.unwrap())); } } /// Appends a child to this node. /// /// # Panics /// /// Panics if `new_child_id` is not valid. pub fn append_id(&mut self, new_child_id: NodeId) -> NodeMut { let last_child_id = self.node().children.map(|(_, id)| id); { let mut new_child = self.tree.get_mut(new_child_id).unwrap(); new_child.detach(); new_child.node().parent = Some(self.id); new_child.node().prev_sibling = last_child_id; } if let Some(id) = last_child_id { unsafe { self.tree.node_mut(id).next_sibling = Some(new_child_id); } } { if let Some((first_child_id, _)) = self.node().children { self.node().children = Some((first_child_id, new_child_id)); } else { self.node().children = Some((new_child_id, new_child_id)); } } unsafe { self.tree.get_unchecked_mut(new_child_id) } } /// Prepends a child to this node. /// /// # Panics /// /// Panics if `new_child_id` is not valid. pub fn prepend_id(&mut self, new_child_id: NodeId) -> NodeMut { let first_child_id = self.node().children.map(|(id, _)| id); { let mut new_child = self.tree.get_mut(new_child_id).unwrap(); new_child.detach(); new_child.node().parent = Some(self.id); new_child.node().next_sibling = first_child_id; } if let Some(id) = first_child_id { unsafe { self.tree.node_mut(id).prev_sibling = Some(new_child_id); } } { if let Some((_, last_child_id)) = self.node().children { self.node().children = Some((new_child_id, last_child_id)); } else { self.node().children = Some((new_child_id, new_child_id)); } } unsafe { self.tree.get_unchecked_mut(new_child_id) } } /// Inserts a sibling before this node. /// /// # Panics /// /// - Panics if `new_sibling_id` is not valid. /// - Panics if this node is an orphan. pub fn insert_id_before(&mut self, new_sibling_id: NodeId) -> NodeMut { let parent_id = self.node().parent.unwrap(); let prev_sibling_id = self.node().prev_sibling; { let mut new_sibling = self.tree.get_mut(new_sibling_id).unwrap(); new_sibling.node().parent = Some(parent_id); new_sibling.node().prev_sibling = prev_sibling_id; new_sibling.node().next_sibling = Some(self.id); } if let Some(id) = prev_sibling_id { unsafe { self.tree.node_mut(id).next_sibling = Some(new_sibling_id); } } self.node().prev_sibling = Some(new_sibling_id); { let parent = unsafe { self.tree.node_mut(parent_id) }; let (first_child_id, last_child_id) = parent.children.unwrap(); if first_child_id == self.id { parent.children = Some((new_sibling_id, last_child_id)); } } unsafe { self.tree.get_unchecked_mut(new_sibling_id) } } /// Inserts a sibling after this node. /// /// # Panics /// /// - Panics if `new_sibling_id` is not valid. /// - Panics if this node is an orphan. pub fn insert_id_after(&mut self, new_sibling_id: NodeId) -> NodeMut { let parent_id = self.node().parent.unwrap(); let next_sibling_id = self.node().next_sibling; { let mut new_sibling = self.tree.get_mut(new_sibling_id).unwrap(); new_sibling.node().parent = Some(parent_id); new_sibling.node().prev_sibling = Some(self.id); new_sibling.node().next_sibling = next_sibling_id; } if let Some(id) = next_sibling_id { unsafe { self.tree.node_mut(id).prev_sibling = Some(new_sibling_id); } } self.node().next_sibling = Some(new_sibling_id); { let parent = unsafe { self.tree.node_mut(parent_id) }; let (first_child_id, last_child_id) = parent.children.unwrap(); if last_child_id == self.id { parent.children = Some((first_child_id, new_sibling_id)); } } unsafe { self.tree.get_unchecked_mut(new_sibling_id) } } /// Reparents the children of a node, appending them to this node. /// /// # Panics /// /// Panics if `from_id` is not valid. pub fn reparent_from_id_append(&mut self, from_id: NodeId) { let new_child_ids = { let mut from = self.tree.get_mut(from_id).unwrap(); match from.node().children.take() { Some(ids) => ids, None => return, } }; unsafe { self.tree.node_mut(new_child_ids.0).parent = Some(self.id); self.tree.node_mut(new_child_ids.1).parent = Some(self.id); } if self.node().children.is_none() { self.node().children = Some(new_child_ids); return; } let old_child_ids = self.node().children.unwrap(); unsafe { self.tree.node_mut(old_child_ids.1).next_sibling = Some(new_child_ids.0); self.tree.node_mut(new_child_ids.0).prev_sibling = Some(old_child_ids.1); } self.node().children = Some((old_child_ids.0, new_child_ids.1)); } /// Reparents the children of a node, prepending them to this node. /// /// # Panics /// /// Panics if `from_id` is not valid. pub fn reparent_from_id_prepend(&mut self, from_id: NodeId) { let new_child_ids = { let mut from = self.tree.get_mut(from_id).unwrap(); match from.node().children.take() { Some(ids) => ids, None => return, } }; unsafe { self.tree.node_mut(new_child_ids.0).parent = Some(self.id); self.tree.node_mut(new_child_ids.1).parent = Some(self.id); } if self.node().children.is_none() { self.node().children = Some(new_child_ids); return; } let old_child_ids = self.node().children.unwrap(); unsafe { self.tree.node_mut(old_child_ids.0).prev_sibling = Some(new_child_ids.1); self.tree.node_mut(new_child_ids.1).next_sibling = Some(old_child_ids.0); } self.node().children = Some((new_child_ids.0, old_child_ids.1)); } } impl<'a, T: 'a> From> for NodeRef<'a, T> { fn from(node: NodeMut<'a, T>) -> Self { unsafe { node.tree.get_unchecked(node.id) } } } /// Iterators. pub mod iter; /// Creates a tree from expressions. /// /// # Examples /// /// ``` /// #[macro_use] extern crate ego_tree; /// # fn main() { /// let tree = tree!("root"); /// # } /// ``` /// /// ``` /// #[macro_use] extern crate ego_tree; /// # fn main() { /// let tree = tree! { /// "root" => { /// "child a", /// "child b" => { /// "grandchild a", /// "grandchild b", /// }, /// "child c", /// } /// }; /// # } /// ``` #[macro_export] macro_rules! tree { (@ $n:ident { }) => { }; // Last leaf. (@ $n:ident { $value:expr }) => { { $n.append($value); } }; // Leaf. (@ $n:ident { $value:expr, $($tail:tt)* }) => { { $n.append($value); tree!(@ $n { $($tail)* }); } }; // Last node with children. (@ $n:ident { $value:expr => $children:tt }) => { { let mut node = $n.append($value); tree!(@ node $children); } }; // Node with children. (@ $n:ident { $value:expr => $children:tt, $($tail:tt)* }) => { { { let mut node = $n.append($value); tree!(@ node $children); } tree!(@ $n { $($tail)* }); } }; ($root:expr) => { $crate::Tree::new($root) }; ($root:expr => $children:tt) => { { let mut tree = $crate::Tree::new($root); { let mut node = tree.root_mut(); tree!(@ node $children); } tree } }; } impl Debug for Tree { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { use iter::Edge; if f.alternate() { write!(f, "Tree {{")?; for edge in self.root().traverse() { match edge { Edge::Open(node) if node.has_children() => { write!(f, " {:?} => {{", node.value())?; }, Edge::Open(node) if node.next_sibling().is_some() => { write!(f, " {:?},", node.value())?; }, Edge::Open(node) => { write!(f, " {:?}", node.value())?; }, Edge::Close(node) if node.has_children() => { if node.next_sibling().is_some() { write!(f, " }},")?; } else { write!(f, " }}")?; } }, _ => {}, } } write!(f, " }}") } else { f.debug_struct("Tree").field("vec", &self.vec).finish() } } } ego-tree-0.6.2/tests/iter.rs010064400007650000024000000074441354517746200141470ustar0000000000000000#[macro_use] extern crate ego_tree; #[test] fn into_iter() { let tree = tree!('a' => { 'b', 'c', 'd' }); assert_eq!( vec!['a', 'b', 'c', 'd'], tree.into_iter().collect::>() ); } #[test] fn values() { let tree = tree!('a' => { 'b', 'c', 'd' }); assert_eq!( vec![&'a', &'b', &'c', &'d'], tree.values().collect::>() ); } #[test] fn values_mut() { let mut tree = tree!('a' => { 'b', 'c', 'd' }); for c in tree.values_mut() { *c = c.to_ascii_uppercase(); } assert_eq!( vec![&'A', &'B', &'C', &'D'], tree.values().collect::>() ); } #[test] fn nodes() { let mut tree = tree!('a' => { 'b' => { 'c' }, 'd' }); tree.orphan('e').append('f'); tree.root_mut().append('g'); assert_eq!( vec![&'a', &'b', &'c', &'d', &'e', &'f', &'g'], tree.nodes().map(|n| n.value()).collect::>() ); } #[test] fn ancestors() { let tree = tree!('a' => { 'b' => { 'c' => { 'd' } } }); let d = tree.root() .last_child().unwrap() .last_child().unwrap() .last_child().unwrap(); assert_eq!( vec![&'c', &'b', &'a'], d.ancestors().map(|n| n.value()).collect::>() ); } #[test] fn prev_siblings() { let tree = tree!('a' => { 'b', 'c', 'd' }); assert_eq!( vec![&'c', &'b'], tree.root() .last_child() .unwrap() .prev_siblings() .map(|n| n.value()) .collect::>() ); } #[test] fn next_siblings() { let tree = tree!('a' => { 'b', 'c', 'd' }); assert_eq!( vec![&'c', &'d'], tree.root() .first_child() .unwrap() .next_siblings() .map(|n| n.value()) .collect::>() ); } #[test] fn children() { let tree = tree!('a' => { 'b', 'c', 'd' }); assert_eq!( vec![&'b', &'c', &'d'], tree.root().children().map(|n| n.value()).collect::>() ); } #[test] fn children_rev() { let tree = tree!('a' => { 'b', 'c', 'd' }); assert_eq!( vec![&'d', &'c', &'b'], tree.root().children().rev().map(|n| n.value()).collect::>() ); } #[test] fn first_children() { let tree = tree!('a' => { 'b' => { 'd', 'e' }, 'c' }); assert_eq!( vec![&'b', &'d'], tree.root().first_children().map(|n| n.value()).collect::>() ); } #[test] fn last_children() { let tree = tree!('a' => { 'b', 'c' => { 'd', 'e' } }); assert_eq!( vec![&'c', &'e'], tree.root().last_children().map(|n| n.value()).collect::>() ); } #[test] fn traverse() { use ego_tree::iter::Edge; #[derive(Debug, PartialEq, Eq)] enum Value<'a> { Open(&'a char), Close(&'a char), } let tree = tree!('a' => { 'b' => { 'd', 'e' }, 'c' }); let traversal = tree.root().traverse().map(|edge| { match edge { Edge::Open(node) => Value::Open(node.value()), Edge::Close(node) => Value::Close(node.value()), } }).collect::>(); assert_eq!( &[ Value::Open(&'a'), Value::Open(&'b'), Value::Open(&'d'), Value::Close(&'d'), Value::Open(&'e'), Value::Close(&'e'), Value::Close(&'b'), Value::Open(&'c'), Value::Close(&'c'), Value::Close(&'a'), ], &traversal[..] ); } #[test] fn descendants() { let tree = tree!('a' => { 'b' => { 'd', 'e' }, 'c' }); let descendants = tree.root().descendants().map(|n| n.value()).collect::>(); assert_eq!( &[ &'a', &'b', &'d', &'e', &'c', ], &descendants[..] ); } ego-tree-0.6.2/tests/macro.rs010064400007650000024000000065401326672160700142750ustar0000000000000000#[macro_use] extern crate ego_tree; use ego_tree::Tree; #[test] fn root() { let macro_tree = tree!('a'); let manual_tree = Tree::new('a'); assert_eq!(manual_tree, macro_tree); } #[test] fn single_child() { let macro_tree = tree!('a' => { 'b' }); let mut manual_tree = Tree::new('a'); manual_tree.root_mut().append('b'); assert_eq!(manual_tree, macro_tree); } #[test] fn single_child_comma() { let macro_tree = tree! { 'a' => { 'b', } }; let mut manual_tree = Tree::new('a'); manual_tree.root_mut().append('b'); assert_eq!(manual_tree, macro_tree); } #[test] fn leaves() { let macro_tree = tree!('a' => { 'b', 'c', 'd' }); let mut manual_tree = Tree::new('a'); manual_tree.root_mut().append('b'); manual_tree.root_mut().append('c'); manual_tree.root_mut().append('d'); assert_eq!(manual_tree, macro_tree); } #[test] fn leaves_comma() { let macro_tree = tree! { 'a' => { 'b', 'c', 'd', } }; let mut manual_tree = Tree::new('a'); manual_tree.root_mut().append('b'); manual_tree.root_mut().append('c'); manual_tree.root_mut().append('d'); assert_eq!(manual_tree, macro_tree); } #[test] fn nested_single_child() { let macro_tree = tree!('a' => { 'b' => { 'c' } }); let mut manual_tree = Tree::new('a'); manual_tree.root_mut().append('b').append('c'); assert_eq!(manual_tree, macro_tree); } #[test] fn nested_single_child_comma() { let macro_tree = tree! { 'a' => { 'b' => { 'c', }, } }; let mut manual_tree = Tree::new('a'); manual_tree.root_mut().append('b').append('c'); assert_eq!(manual_tree, macro_tree); } #[test] fn nested_leaves() { let macro_tree = tree!('a' => { 'b' => { 'c', 'd', 'e' } }); let mut manual_tree = Tree::new('a'); { let mut root = manual_tree.root_mut(); let mut node = root.append('b'); node.append('c'); node.append('d'); node.append('e'); } assert_eq!(manual_tree, macro_tree); } #[test] fn nested_leaves_comma() { let macro_tree = tree! { 'a' => { 'b' => { 'c', 'd', 'e', }, } }; let mut manual_tree = Tree::new('a'); { let mut root = manual_tree.root_mut(); let mut node = root.append('b'); node.append('c'); node.append('d'); node.append('e'); } assert_eq!(manual_tree, macro_tree); } #[test] fn nested_nested() { let macro_tree = tree!('a' => { 'b' => { 'c' => { 'd' } } }); let mut manual_tree = Tree::new('a'); manual_tree.root_mut().append('b').append('c').append('d'); assert_eq!(manual_tree, macro_tree); } #[test] fn mixed() { let macro_tree = tree! { 'a' => { 'b', 'd' => { 'e', 'f' }, 'g' => { 'h' => { 'i' } }, 'j', } }; let mut manual_tree = Tree::new('a'); { let mut node = manual_tree.root_mut(); node.append('b'); { let mut d = node.append('d'); d.append('e'); d.append('f'); } node.append('g').append('h').append('i'); node.append('j'); } assert_eq!(manual_tree, macro_tree); } ego-tree-0.6.2/tests/node_mut.rs010064400007650000024000000222201354517746200150030ustar0000000000000000#[macro_use] extern crate ego_tree; use ego_tree::NodeRef; #[test] fn value() { let mut tree = tree!('a'); assert_eq!(&'a', tree.root_mut().value()); } #[test] fn parent() { let mut tree = tree!('a' => { 'b' }); assert_eq!( &'a', tree.root_mut() .first_child() .unwrap() .parent() .unwrap() .value() ); } #[test] fn prev_sibling() { let mut tree = tree!('a' => { 'b', 'c' }); assert_eq!( &'b', tree.root_mut() .last_child() .unwrap() .prev_sibling() .unwrap() .value() ); } #[test] fn next_sibling() { let mut tree = tree!('a' => { 'b', 'c' }); assert_eq!( &'c', tree.root_mut() .first_child() .unwrap() .next_sibling() .unwrap() .value() ); } #[test] fn first_child() { let mut tree = tree!('a' => { 'b', 'c' }); assert_eq!(&'b', tree.root_mut().first_child().unwrap().value()); } #[test] fn last_child() { let mut tree = tree!('a' => { 'b', 'c' }); assert_eq!(&'c', tree.root_mut().last_child().unwrap().value()); } #[test] fn has_siblings() { let mut tree = tree!('a' => { 'b', 'c' }); assert_eq!(true, tree.root_mut().first_child().unwrap().has_siblings()); assert_eq!(false, tree.root_mut().has_siblings()); } #[test] fn has_children() { let mut tree = tree!('a' => { 'b', 'c' }); assert_eq!(true, tree.root_mut().has_children()); assert_eq!(false, tree.root_mut().first_child().unwrap().has_children()); } #[test] fn append_1() { let mut tree = tree!('a'); tree.root_mut().append('b'); let root = tree.root(); let child = root.first_child().unwrap(); assert_eq!(&'b', child.value()); assert_eq!(Some(child), root.last_child()); assert_eq!(Some(root), child.parent()); assert_eq!(None, child.next_sibling()); assert_eq!(None, child.next_sibling()); } #[test] fn append_2() { let mut tree = tree!('a'); tree.root_mut().append('b'); tree.root_mut().append('c'); let root = tree.root(); let b = root.first_child().unwrap(); let c = root.last_child().unwrap(); assert_eq!(&'b', b.value()); assert_eq!(&'c', c.value()); assert_eq!(Some(root), b.parent()); assert_eq!(Some(root), c.parent()); assert_eq!(None, b.prev_sibling()); assert_eq!(Some(c), b.next_sibling()); assert_eq!(Some(b), c.prev_sibling()); assert_eq!(None, c.next_sibling()); } #[test] fn append_3() { let mut tree = tree!('a'); tree.root_mut().append('b'); tree.root_mut().append('c'); tree.root_mut().append('d'); let root = tree.root(); let b = root.first_child().unwrap(); let c = b.next_sibling().unwrap(); let d = root.last_child().unwrap(); assert_eq!(&'b', b.value()); assert_eq!(&'c', c.value()); assert_eq!(&'d', d.value()); assert_eq!(Some(root), b.parent()); assert_eq!(Some(root), c.parent()); assert_eq!(Some(root), d.parent()); assert_eq!(None, b.prev_sibling()); assert_eq!(Some(c), b.next_sibling()); assert_eq!(Some(b), c.prev_sibling()); assert_eq!(Some(d), c.next_sibling()); assert_eq!(Some(c), d.prev_sibling()); assert_eq!(None, d.next_sibling()); } #[test] fn prepend_1() { let mut tree = tree!('a'); tree.root_mut().prepend('b'); let root = tree.root(); let child = root.first_child().unwrap(); assert_eq!(&'b', child.value()); assert_eq!(Some(child), root.last_child()); assert_eq!(Some(root), child.parent()); assert_eq!(None, child.next_sibling()); assert_eq!(None, child.next_sibling()); } #[test] fn prepend_2() { let mut tree = tree!('a'); tree.root_mut().prepend('c'); tree.root_mut().prepend('b'); let root = tree.root(); let b = root.first_child().unwrap(); let c = root.last_child().unwrap(); assert_eq!(&'b', b.value()); assert_eq!(&'c', c.value()); assert_eq!(Some(root), b.parent()); assert_eq!(Some(root), c.parent()); assert_eq!(None, b.prev_sibling()); assert_eq!(Some(c), b.next_sibling()); assert_eq!(Some(b), c.prev_sibling()); assert_eq!(None, c.next_sibling()); } #[test] fn prepend_3() { let mut tree = tree!('a'); tree.root_mut().prepend('d'); tree.root_mut().prepend('c'); tree.root_mut().prepend('b'); let root = tree.root(); let b = root.first_child().unwrap(); let c = b.next_sibling().unwrap(); let d = root.last_child().unwrap(); assert_eq!(&'b', b.value()); assert_eq!(&'c', c.value()); assert_eq!(&'d', d.value()); assert_eq!(Some(root), b.parent()); assert_eq!(Some(root), c.parent()); assert_eq!(Some(root), d.parent()); assert_eq!(None, b.prev_sibling()); assert_eq!(Some(c), b.next_sibling()); assert_eq!(Some(b), c.prev_sibling()); assert_eq!(Some(d), c.next_sibling()); assert_eq!(Some(c), d.prev_sibling()); assert_eq!(None, d.next_sibling()); } #[test] fn insert_before_first() { let mut tree = tree!('a' => { 'c' }); tree.root_mut().first_child().unwrap().insert_before('b'); let root = tree.root(); let b = root.first_child().unwrap(); let c = root.last_child().unwrap(); assert_eq!(&'b', b.value()); assert_eq!(Some(root), b.parent()); assert_eq!(None, b.prev_sibling()); assert_eq!(Some(c), b.next_sibling()); assert_eq!(Some(b), c.prev_sibling()); assert_eq!(None, c.next_sibling()); } #[test] fn insert_before() { let mut tree = tree!('a' => { 'b', 'd' }); tree.root_mut().last_child().unwrap().insert_before('c'); let root = tree.root(); let b = root.first_child().unwrap(); let c = b.next_sibling().unwrap(); let d = root.last_child().unwrap(); assert_eq!(&'c', c.value()); assert_eq!(Some(root), b.parent()); assert_eq!(Some(root), c.parent()); assert_eq!(Some(root), d.parent()); assert_eq!(None, b.prev_sibling()); assert_eq!(Some(c), b.next_sibling()); assert_eq!(Some(b), c.prev_sibling()); assert_eq!(Some(d), c.next_sibling()); assert_eq!(Some(c), d.prev_sibling()); assert_eq!(None, d.next_sibling()); } #[test] fn insert_after_first() { let mut tree = tree!('a' => { 'b' }); tree.root_mut().first_child().unwrap().insert_after('c'); let root = tree.root(); let b = root.first_child().unwrap(); let c = root.last_child().unwrap(); assert_eq!(&'c', c.value()); assert_eq!(Some(root), c.parent()); assert_eq!(None, b.prev_sibling()); assert_eq!(Some(c), b.next_sibling()); assert_eq!(Some(b), c.prev_sibling()); assert_eq!(None, c.next_sibling()); } #[test] fn insert_after() { let mut tree = tree!('a' => { 'b', 'd' }); tree.root_mut().first_child().unwrap().insert_after('c'); let root = tree.root(); let b = root.first_child().unwrap(); let c = b.next_sibling().unwrap(); let d = root.last_child().unwrap(); assert_eq!(&'c', c.value()); assert_eq!(Some(root), b.parent()); assert_eq!(Some(root), c.parent()); assert_eq!(Some(root), d.parent()); assert_eq!(None, b.prev_sibling()); assert_eq!(Some(c), b.next_sibling()); assert_eq!(Some(b), c.prev_sibling()); assert_eq!(Some(d), c.next_sibling()); assert_eq!(Some(c), d.prev_sibling()); assert_eq!(None, d.next_sibling()); } #[test] fn detach() { let mut tree = tree!('a' => { 'b', 'd' }); let mut root = tree.root_mut(); let mut b = root.first_child().unwrap(); let mut c = b.insert_after('c'); c.detach(); assert!(c.parent().is_none()); assert!(c.prev_sibling().is_none()); assert!(c.next_sibling().is_none()); } #[test] fn reparent_from_id_append() { let mut tree = tree! { 'a' => { 'b' => { 'c', 'd' }, 'e' => { 'f', 'g' }, } }; let e_id = tree.root().last_child().unwrap().id(); tree.root_mut().first_child().unwrap().reparent_from_id_append(e_id); let b = tree.root().first_child().unwrap(); let e = tree.root().last_child().unwrap(); let d = b.first_child().unwrap().next_sibling().unwrap(); let g = b.last_child().unwrap(); let f = g.prev_sibling().unwrap(); assert_eq!(false, e.has_children()); assert_eq!(&'f', f.value()); assert_eq!(&'g', g.value()); assert_eq!(Some(f), d.next_sibling()); assert_eq!(Some(d), f.prev_sibling()); } #[test] fn reparent_from_id_prepend() { let mut tree = tree! { 'a' => { 'b' => { 'f', 'g' }, 'e' => { 'c', 'd' }, } }; let e_id = tree.root().last_child().unwrap().id(); tree.root_mut().first_child().unwrap().reparent_from_id_prepend(e_id); let b = tree.root().first_child().unwrap(); let e = tree.root().last_child().unwrap(); let c = b.first_child().unwrap(); let d = c.next_sibling().unwrap(); let f = b.last_child().unwrap().prev_sibling().unwrap(); assert_eq!(false, e.has_children()); assert_eq!(&'c', c.value()); assert_eq!(&'d', d.value()); assert_eq!(Some(f), d.next_sibling()); assert_eq!(Some(d), f.prev_sibling()); } #[test] fn into() { let mut tree = tree!('a'); let node_ref: NodeRef<_> = tree.root_mut().into(); assert_eq!(&'a', node_ref.value()); } ego-tree-0.6.2/tests/node_ref.rs010064400007650000024000000034461326741765600147660ustar0000000000000000#[macro_use] extern crate ego_tree; #[test] fn value() { let tree = tree!('a'); assert_eq!(&'a', tree.root().value()); } #[test] fn parent() { let tree = tree!('a' => { 'b' }); let b = tree.root().first_child().unwrap(); assert_eq!(tree.root(), b.parent().unwrap()); } #[test] fn prev_sibling() { let tree = tree!('a' => { 'b', 'c' }); let c = tree.root().last_child().unwrap(); assert_eq!(tree.root().first_child(), c.prev_sibling()); } #[test] fn next_sibling() { let tree = tree!('a' => { 'b', 'c' }); let b = tree.root().first_child().unwrap(); assert_eq!(tree.root().last_child(), b.next_sibling()); } #[test] fn first_child() { let tree = tree!('a' => { 'b', 'c' }); assert_eq!(&'b', tree.root().first_child().unwrap().value()); } #[test] fn last_child() { let tree = tree!('a' => { 'b', 'c' }); assert_eq!(&'c', tree.root().last_child().unwrap().value()); } #[test] fn has_siblings() { let tree = tree!('a' => { 'b', 'c' }); assert_eq!(false, tree.root().has_siblings()); assert_eq!(true, tree.root().first_child().unwrap().has_siblings()); } #[test] fn has_children() { let tree = tree!('a' => { 'b', 'c' }); assert_eq!(true, tree.root().has_children()); assert_eq!(false, tree.root().first_child().unwrap().has_children()); } #[test] fn clone() { let tree = tree!('a'); let one = tree.root(); let two = one.clone(); assert_eq!(one, two); } #[test] fn eq() { let tree = tree!('a'); assert_eq!(tree.root(), tree.root()); } #[test] #[should_panic] fn neq() { let tree = tree!('a' => { 'b', 'c' }); assert_eq!(tree.root(), tree.root().first_child().unwrap()); } #[test] #[should_panic] fn neq_tree() { let one = tree!('a'); let two = one.clone(); assert_eq!(one.root(), two.root()); } ego-tree-0.6.2/tests/tree.rs010064400007650000024000000025461354517746200141410ustar0000000000000000extern crate ego_tree; use ego_tree::Tree; #[test] fn new() { let tree = Tree::new('a'); let root = tree.root(); assert_eq!(&'a', root.value()); assert_eq!(None, root.parent()); assert_eq!(None, root.prev_sibling()); assert_eq!(None, root.next_sibling()); assert_eq!(None, root.first_child()); assert_eq!(None, root.last_child()); } #[test] fn root() { let tree = Tree::new('a'); assert_eq!(&'a', tree.root().value()); } #[test] fn root_mut() { let mut tree = Tree::new('a'); assert_eq!(&'a', tree.root_mut().value()); } #[test] fn orphan() { let mut tree = Tree::new('a'); let mut orphan = tree.orphan('b'); assert_eq!(&'b', orphan.value()); assert!(orphan.parent().is_none()); } #[test] fn get() { let tree = Tree::new('a'); let id = tree.root().id(); assert_eq!(Some(tree.root()), tree.get(id)); } #[test] fn get_mut() { let mut tree = Tree::new('a'); let id = tree.root().id(); assert_eq!(Some('a'), tree.get_mut(id).map(|mut n| *n.value())); } #[test] fn clone() { let one = Tree::new('a'); let two = one.clone(); assert_eq!(one, two); } #[test] fn eq() { let one = Tree::new('a'); let two = Tree::new('a'); assert_eq!(one, two); } #[test] #[should_panic] fn neq() { let one = Tree::new('a'); let two = Tree::new('b'); assert_eq!(one, two); } ego-tree-0.6.2/.cargo_vcs_info.json0000644000000001120000000000000126010ustar00{ "git": { "sha1": "2778773740d89b61b98e078a5ebe22a87a2bda6e" } }