list_fn/
list.rs

1pub struct ListSome<F: ListFn> {
2    pub first: F::Item,
3    pub next: F,
4}
5
6/// A list.
7pub enum ListState<F: ListFn> {
8    Some(ListSome<F>),
9    /// The end of the list.
10    End(F::End),
11}
12
13impl<F: ListFn> ListState<F> {
14    pub fn some(first: F::Item, next: F) -> Self {
15        ListState::Some(ListSome { first, next })
16    }
17    pub fn unwrap(self) -> ListSome<F> {
18        match self {
19            ListState::Some(v) => v,
20            ListState::End(_) => panic!(),
21        }
22    }
23}
24
25/// A function which returns a list.
26pub trait ListFn: Sized {
27    /// A list item type.
28    type Item;
29    /// A value which is returned when the list has no more items.
30    type End;
31    /// The main function which returns a list.
32    fn next(self) -> ListState<Self>;
33}