Struct cactus::Cactus
[−]
[src]
pub struct Cactus<T> { /* fields omitted */ }
An immutable cactus stack node. May be empty or contain a value; may have a pointer to a parent or not.
Methods
impl<T> Cactus<T>
[src]
fn new() -> Cactus<T>
Return an empty cactus stack node.
fn is_empty(&self) -> bool
Is this cactus stack node empty?
Examples
use cactus::Cactus; let c = Cactus::new(); assert!(c.is_empty()); let c2 = c.child(1); assert!(!c2.is_empty());
fn len(&self) -> usize
How many items are there in this cactus stack?
fn child(&self, val: T) -> Cactus<T>
Create a new cactus stack node containing value val
and pointing to parent self
.
Examples
use cactus::Cactus; let c = Cactus::new(); let c2 = c.child(1); let c3 = c2.child(2); assert_eq!(c3.vals().cloned().collect::<Vec<_>>(), [2, 1]);
fn parent(&self) -> Option<Cactus<T>>
Return this cactus stack node's parent node or None
if this cactus stack is empty.
Examples
use cactus::Cactus; let c = Cactus::new(); let c2 = c.child(1); assert_eq!(c.parent(), None); assert_eq!(c2.val(), Some(&1)); assert_eq!(c2.parent().unwrap(), Cactus::new());
fn val(&self) -> Option<&T>
Return a reference to this cactus stack node's value or None
if this cactus stack is
empty.
Examples
use cactus::Cactus; let c = Cactus::new().child(1); assert_eq!(c.val(), Some(&1)); assert_eq!(c.parent().unwrap().val(), None);
fn nodes(&self) -> CactusNodesIter<T>
Return an iterator over this cactus stack's nodes. Note that the iterator produces nodes starting from this node and then walking up towards the root.
Examples
use cactus::Cactus; let c = Cactus::new().child(1).child(2).child(3); assert_eq!(c.nodes().skip(1).next(), Some(Cactus::new().child(1).child(2)));
fn vals(&self) -> CactusValsIter<T>
Return an iterator over this cactus stack's values. Note that the iterator produces values starting from this node and then walking up towards the root.
Examples
use cactus::Cactus; let c = Cactus::new().child(1).child(2).child(3); assert_eq!(c.vals().cloned().collect::<Vec<_>>(), [3, 2, 1]);
Trait Implementations
impl<T: Clone> Clone for Cactus<T>
[src]
fn clone(&self) -> Cactus<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Default> Default for Cactus<T>
[src]
impl<T: PartialEq> PartialEq for Cactus<T>
[src]
fn eq(&self, other: &Cactus<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.