Diffstat (limited to 'src/impls/core/bool.rs')
| -rw-r--r-- | src/impls/core/bool.rs | 64 |
1 files changed, 7 insertions, 57 deletions
diff --git a/src/impls/core/bool.rs b/src/impls/core/bool.rs index cdc1337..e1460ee 100644 --- a/src/impls/core/bool.rs +++ b/src/impls/core/bool.rs @@ -1,67 +1,17 @@ -use core::any::TypeId; - use crate::{ - build::{Build, Builder}, - implementer, - protocol::{Implementer, ImplementerExt}, - protocols::{bool, ControlFlow}, - walk::WalkOnce, + build::{builders::OwnedBuilder, Build}, + walk::walkers::OwnedCloneWalker, + Walk, }; #[derive(thiserror::Error, Debug)] #[error("The value is complete.")] pub struct IncompleteValue; -#[derive(Default)] -pub struct BoolBuilder(Option<bool>); - -impl<'ctx> Build<'ctx> for bool { - type Builder = BoolBuilder; -} - -impl<'ctx> Builder<'ctx> for BoolBuilder { - type Error = IncompleteValue; - - type Value = bool; - - fn as_visitor(&mut self) -> &mut dyn crate::protocol::Implementer<'ctx> { - self - } - - fn build(self) -> Result<Self::Value, Self::Error> { - match self.0 { - Some(value) => Ok(value), - None => Err(IncompleteValue), - } - } - - fn accepts(id: core::any::TypeId) -> bool { - id == TypeId::of::<bool::Bool>() - } +impl<'ctx> Walk<'ctx> for bool { + type Walker = OwnedCloneWalker<Self>; } -implementer! { - impl['ctx] BoolBuilder = [bool::Bool]; -} - -impl<'ctx> bool::Object<'ctx> for BoolBuilder { - fn visit(&mut self, value: bool) -> crate::protocols::ControlFlow { - self.0 = Some(value); - ControlFlow::Done - } -} - -impl<'ctx> WalkOnce<'ctx> for bool { - type Error = (); - - type Value = (); - - #[inline] - fn walk_once(self, visitor: &mut dyn Implementer<'ctx>) -> Result<Self::Value, Self::Error> { - if let Some(interface) = visitor.interface_for::<bool::Bool>() { - interface.as_object().visit(self); - } - - Ok(()) - } +impl<'ctx> Build<'ctx> for bool { + type Builder = OwnedBuilder<Self>; } |