agenda 0.0.1

Safe collections that can be mutated while being iterated through
Documentation
use std::cell::Cell;

pub struct List<T> {
    head: Cell<ListNode<T>>,
}

#[derive(Debug)]
enum ListNode<T> {
    Nil,
    Val {
        elem: T,
        next: Box<ListNode<T>>,
    }
}

impl<T> Default for ListNode<T> {
    fn default() -> Self { ListNode::Nil }
}

impl<T> List<T> {
    pub fn new() -> List<T> {
        List { head: Cell::new(ListNode::Nil), }
    }
    pub fn push(&self, elem: T) {
        let next = Box::new(self.head.take());
        let node = ListNode::Val { elem, next };
        self.head.set(node);
    }
    pub fn pop(&self) -> Option<T> {
        match self.head.take() {
            ListNode::Val { elem, next } => {
                self.head.set(*next);
                Some(elem)
            }
            ListNode::Nil => None,
        }
    }
    pub fn iter(&self) -> &Self {
        self
    }
}

impl<'a, T> Iterator for &'a List<T> {
    type Item = T;
    fn next(&mut self) -> Option<T> {
        self.pop()
    }

}