hkt_pin_list/
lib.rs

1#![no_std]
2
3mod list;
4mod macros;
5mod node;
6mod util;
7#[doc(hidden)]
8pub mod hkt;
9
10pub use list::{iter::Iter, LinkedList};
11pub use node::{ptr::NodePtr, Link, Node};
12
13#[cfg(test)]
14mod tests {
15    use core::pin::pin;
16
17    use crate::LinkedList;
18
19    use super::Node;
20
21    extern crate alloc;
22
23    #[test]
24    fn test() {
25        let mut list = pin!(<LinkedList!(i32)>::new());
26        let list2 = pin!(<LinkedList!(i32)>::new());
27        let list2 = list2.into_ref();
28
29        let node1 = pin!(Node::new(1234));
30        let node1 = node1.into_ref();
31        let node2 = pin!(Node::new(5678));
32        let node2 = node2.into_ref();
33        list.as_ref().push_front(node2);
34        list.as_ref().push_front(node1);
35
36        let list = list.as_mut();
37
38        list2.push_front(node1);
39        node1.unlink();
40        list.as_ref().push_front(node1);
41
42        list.as_ref().take(|list| {
43            list.iter(|mut iter| {
44                assert_eq!(iter.next().map(|node| node.get_ref().value()), Some(&1234));
45                let _a = node1;
46                let _b = node2;
47                assert_eq!(iter.next().map(|node| node.get_ref().value()), Some(&5678));
48                assert_eq!(iter.next().map(|node| node.get_ref().value()), None);
49            });
50        });
51    }
52}