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
52
53
use core::ops::ControlFlow;

use crate::{
    any::static_wrapper::OwnedStatic,
    any_trait,
    protocol::{visitor::Value, ControlFlowFor, Effect, SyncEffect},
};

impl<'ctx> crate::Build<'ctx> for bool {
    type Builder = Builder;
}

#[derive(Debug)]
pub enum Error {
    Incomplete,
}

pub struct Builder(Option<bool>);

impl<'ctx> crate::Builder<'ctx> for Builder {
    type Error = Error;

    type Value = bool;

    fn as_visitor(&mut self) -> &mut crate::protocol::Visitor<'_, 'ctx> {
        self
    }

    #[inline]
    fn build(self) -> Result<Self::Value, Self::Error> {
        self.0.ok_or(Error::Incomplete)
    }

    type Seed = ();

    fn from_seed(seed: Self::Seed) -> Self {
        Self(None)
    }
}

any_trait! {
    impl['a, 'ctx] Builder = [
        dyn Value<'a, OwnedStatic<bool>> + 'a,
    ]
}

impl<'a> Value<'a, OwnedStatic<bool>> for Builder {
    #[inline]
    fn visit(&'a mut self, OwnedStatic(value): OwnedStatic<bool>) -> ControlFlowFor<'a> {
        self.0 = Some(value);
        ControlFlow::Continue(())
    }
}