creating_a_list/creating_a_list.rs
1use kdb::{KBox, List};
2
3fn main() {
4 //Create a list containing the numbers from 1 to 10.
5 let mut list: KBox<List<u8>> = (1..=10).collect();
6
7 //Create another list by pushing incrementally
8 let mut list_2: KBox<List<u8>> = KBox::new_list();
9 for i in 11..=20 {
10 list_2.push(i);
11 }
12
13 //Append the second list to the first
14 list.join(list_2);
15
16 // Append from an iterator:
17 list.extend(21..=30);
18
19 // write out the contents
20 for i in list.iter() {
21 println!("{}", i);
22 }
23
24 // we can also use it as a slice:
25 for i in &list[..5] {
26 println!("{}", i)
27 }
28}