#[test] fn example_one() { use dynamic_list::*; use typenum::*; // Chain access: let array = array![1u8, "hello", true, "world"]; assert_eq!(array.forward().next().value(), &"hello"); assert_eq!(array.backward().value(), &"world"); // Index access: let list = list![1u8, "hello", true, "world"]; assert_eq!(Index::::index(list.forward()), &"hello"); assert_eq!(Index::::index(list.forward()), &"world"); } #[test] fn example_two() { use dynamic_list::{list::Node, *}; // Iterator trait Concat { fn concat(&self) -> String; } impl Concat for Node { fn concat(&self) -> String { self.value().to_string() } } impl Concat for Node { fn concat(&self) -> String { format!("{}{}", self.value().to_string(), self.next().concat()) } } let list = list![1u8, "_hello", -3i32]; assert_eq!(list.forward().concat(), "1_hello-3"); assert_eq!(list.backward().concat(), "-3_hello1"); } #[test] fn example_three() { use dynamic_list::{list::Node, *}; // Polymorphic trait trait Even { fn even(&self) -> usize; } impl> Even for T { fn even(&self) -> usize { (self.clone().try_into().unwrap_or(1) + 1) % 2 } } // Iterator trait NumberEven { fn evens(&self) -> usize; } impl NumberEven for Node { fn evens(&self) -> usize { self.value().even() } } impl NumberEven for Node { fn evens(&self) -> usize { self.value().even() + self.next().evens() } } let list = list![false, 1, 2u8, -3, 4isize]; assert_eq!(list.forward().evens(), 3); }