1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::{
    nameable,
    protocol::{walker::HintMeta, ControlFlow, Visitor},
};

pub trait Sequence<'ctx> {
    fn visit(&mut self, scope: &mut dyn SequenceScope<'ctx>) -> ControlFlow;
}

nameable! {
    pub struct Name['a, 'ctx];
    impl for dyn Sequence<'ctx> + 'a where { 'ctx: 'a }
    impl where dyn Sequence<'ctx> + 'a { 'ctx: 'a }
}

pub trait SequenceScope<'ctx> {
    fn next(&mut self, visitor: Visitor<'_, 'ctx>) -> ControlFlow<(), Status>;
}

#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Debug)]
pub enum Status {
    Done,
    Continue,
}

#[derive(Default)]
pub struct Known {
    pub len: (usize, Option<usize>),
}

pub struct Hint {
    pub len: (usize, Option<usize>),
}

impl<'ctx> HintMeta<'ctx> for dyn Sequence<'ctx> + '_ {
    type Known<'a> = Known
    where
        'ctx: 'a;

    type Hint = Hint;
}