Diffstat (limited to 'src/build/builders/core/bool.rs')
| -rw-r--r-- | src/build/builders/core/bool.rs | 100 |
1 files changed, 14 insertions, 86 deletions
diff --git a/src/build/builders/core/bool.rs b/src/build/builders/core/bool.rs index aa72f20..f6c33b2 100644 --- a/src/build/builders/core/bool.rs +++ b/src/build/builders/core/bool.rs @@ -1,90 +1,18 @@ -use core::{fmt::Display, marker::PhantomData}; +use crate::effect::Effect; -use crate::{ - any::OwnedStatic, - any_trait, - effect::{Effect, ErasedEffective}, - protocol::{ - visitor::{Value, ValueProto, VisitResult}, - DynVisitor, - }, - Flow, -}; +use super::value::{Cloneable, ValueBuilder}; -impl<'ctx, M: 'ctx, E: Effect> crate::Build<'ctx, M, E> for bool { - type Builder = Builder<E>; +macro_rules! value_builder { + [$($ty:ty),*] => { + $(impl<'ctx, M, E: Effect> crate::Build<'ctx, M, E> for $ty { + type Builder = ValueBuilder<$ty, Cloneable, E>; + })* + }; } -#[derive(Debug)] -pub enum Error { - Incomplete, -} - -impl Display for Error { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Error::Incomplete => write!(f, "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(always)] - fn build<'a>(self) -> ErasedEffective<'a, Result<Self::Value, Self::Error>, E> - where - Self: 'a, - { - E::ready(self.0.ok_or(Error::Incomplete)) - } - - #[inline(always)] - fn from_seed<'a>(_seed: Self::Seed) -> ErasedEffective<'a, Self, E> - where - Self: 'a, - { - E::ready(Self(None, PhantomData)) - } - - #[inline(always)] - fn as_visitor(&mut self) -> DynVisitor<'_, 'ctx> { - DynVisitor(self) - } -} - -any_trait! { - impl['ctx, E] Builder<E> = [ - ValueProto<OwnedStatic<bool>, E>, - ] where E: Effect -} - -impl<'ctx, E: Effect> Value<'ctx, OwnedStatic<bool>, E> for Builder<E> { - #[inline(always)] - fn visit<'a>( - &'a mut self, - OwnedStatic(value): OwnedStatic<bool>, - ) -> ErasedEffective<'a, VisitResult<OwnedStatic<bool>>, E> - where - 'ctx: 'a, - { - self.0 = Some(value); - E::ready(Flow::Done.into()) - } -} +value_builder![u8, u16, u32, u64, u128, usize]; +value_builder![i8, i16, i32, i64, i128, isize]; +value_builder![f32, f64]; +value_builder![char]; +value_builder![bool]; +value_builder![()]; |