use core::marker::PhantomData;
use crate::{
any::static_wrapper::{DynOwnedStatic, OwnedStatic},
any_trait,
effect::{Effect, Future},
protocol::{
visitor::value::{DynValue, Value},
Visitor,
},
Flow,
};
impl<'ctx, M, E: Effect> crate::Build<'ctx, M, E> for bool {
type Builder = Builder<E>;
}
#[derive(Debug)]
pub enum Error {
Incomplete,
}
pub struct Builder<E>(Option<bool>, PhantomData<fn() -> E>);
impl crate::BuilderTypes for bool {
type Seed = ();
type Error = Error;
type Value = bool;
}
impl<E> crate::BuilderTypes for Builder<E> {
type Error = Error;
type Value = bool;
type Seed = ();
}
impl<'ctx, E: Effect> crate::Builder<'ctx, E> for Builder<E> {
#[inline]
fn build<'a>(self) -> Future<'a, Result<Self::Value, Self::Error>, E>
where
Self: 'a,
{
E::wrap(core::future::ready(self.0.ok_or(Error::Incomplete)))
}
fn from_seed<'a>(_seed: Self::Seed) -> Future<'a, Self, E>
where
Self: 'a,
{
E::wrap(core::future::ready(Self(None, PhantomData)))
}
fn as_visitor(&mut self) -> Visitor<'_, 'ctx> {
self
}
}
any_trait! {
impl['ctx, E] Builder<E> = [
DynValue<'ctx, DynOwnedStatic<bool>, E>,
] where E: Effect
}
impl<'ctx, E: Effect> Value<'ctx, DynOwnedStatic<bool>, E> for Builder<E> {
#[inline]
fn visit<'a>(&'a mut self, OwnedStatic(value): OwnedStatic<bool>) -> Future<'a, Flow, E>
where
'ctx: 'a
{
self.0 = Some(value);
E::ready(Flow::Continue)
}
}