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
42
43
44
45
46
47
48
49
50
51
use crate::{
    nameable,
    protocol::{walker::HintMeta, ControlFlowFor, Effect, SyncEffect, Visitor},
};

pub trait Sequence<'ctx, E: Effect = SyncEffect> {
    fn visit<'a>(&'a mut self, scope: &'a mut dyn SequenceScope<'ctx, E>) -> ControlFlowFor<'a, E>;
}

nameable! {
    pub struct Name['a, 'ctx, E];

    impl [E] for dyn Sequence<'ctx, E> + 'a where {
        E: Effect + 'static,
        'ctx: 'a
    }

    impl [E] where dyn Sequence<'ctx, E> + 'a {
        E: Effect + 'static,
        'ctx: 'a
    }
}

pub trait SequenceScope<'ctx, E: Effect = SyncEffect> {
    fn next<'a>(&'a mut self, visitor: &'a mut Visitor<'a, 'ctx>) -> ControlFlowFor<'a, E, 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, E: Effect> HintMeta<'ctx> for dyn Sequence<'ctx, E> + '_ {
    type Known<'a> = Known
    where
        'ctx: 'a;

    type Hint<'a> = Hint
    where
        'ctx: 'a;
}