Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 80 |
1 files changed, 76 insertions, 4 deletions
@@ -17,7 +17,10 @@ pub mod symbol; mod transform; mod walk; +use core::ops::ControlFlow; + pub use build::*; +use effect::ConvertShort; pub use transform::*; pub use walk::*; @@ -55,7 +58,11 @@ pub const TAG_ENUM: Symbol = Symbol::new("Enum"); pub enum DefaultMode {} -pub type Status = Result<(), ()>; +#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum Status { + Ok, + Err, +} #[derive(Clone, Copy, PartialEq, Debug)] #[must_use] @@ -67,7 +74,23 @@ pub enum Flow { Done, } +impl ConvertShort<ControlFlow<Flow>> for Option<never::Never> { + fn convert_short(short: Self) -> ControlFlow<Flow> { + match short { + None => ControlFlow::Break(Flow::Done), + Some(_) => unreachable!(), + } + } +} + impl Flow { + pub fn to_status(self) -> Status { + match self { + Flow::Continue | Flow::Done => Status::Ok, + Flow::Err => Status::Err, + } + } + pub fn to_done(self) -> Self { match self { Flow::Continue | Flow::Done => Flow::Done, @@ -81,6 +104,13 @@ impl Flow { Flow::Err => Flow::Err, } } + + pub fn to_control_flow(self) -> ControlFlow<Self> { + match self { + Flow::Continue => ControlFlow::Continue(()), + flow => ControlFlow::Break(flow), + } + } } #[macro_export] @@ -137,7 +167,7 @@ macro_rules! Walk { $(pub const $field: usize = Fields::$field as usize;)* } - use $crate::effect::Effective; + use $crate::effect::EffectiveExt; match index { $(fields::$field => { @@ -154,7 +184,7 @@ macro_rules! Walk { Err(err) => { Err(FieldError(FieldErrorKind::$field(err))) } - }).into_erased() + }) // E::map($crate::Walker::<'ctx, E>::walk(walker, visitor), |result| match result { // Ok(_) => { @@ -165,7 +195,7 @@ macro_rules! Walk { // } // }) })* - _ => E::ready(Ok($crate::Flow::Done)).into_erased() + _ => E::ready(Ok($crate::Flow::Done)) } } } @@ -211,3 +241,45 @@ macro_rules! Walk { // todo!(); // } // } + + +pub mod demo { + use crate::Walk; + use macro_rules_attribute::derive; + use crate::{ + effect::{ + blocking::{BlockOn, Blocking, Spin}, + // r#async::Async, + Effective as _, + }, + transform, Build, DefaultMode, + }; + + #[derive(Walk!, Debug)] + pub struct X { + pub a: bool, + pub b: bool, + pub c: bool, + } + + #[derive(Build!, Debug, PartialEq)] + pub struct Y { + pub a: bool, + pub b: bool, + pub c: bool, + } + + #[inline(never)] + pub fn ident(x: X) -> Y { + let other = + transform::<<Y as crate::Build<'_, DefaultMode, _>>::Builder, _, Blocking<Spin>>( + ((), (), ()), + Walk::<DefaultMode, _>::into_walker(&x), + ) + .value(); + + // let other = Spin::block_on(other.into_future()); + + other.0.unwrap() + } +} |