use super::act::Act;
use core::{
ops::{
FromResidual,
Residual,
Try,
ControlFlow
},
convert::Infallible,
mem::transmute_neo as transmute
};
pub struct Break;
impl<Type> FromResidual<Break> for Act<Type> {
fn from_residual(_residual: Break) -> Self {return unsafe {transmute(None::<Type>)}}
}
impl<Type> FromResidual<Option<Infallible>> for Act<Type> {
fn from_residual(_residual: Option<Infallible>) -> Self {return unsafe {transmute(None::<Type>)}}
}
impl<Type> Residual<Type> for Break {
type TryType = Act<Type>;
}
impl<Type> Try for Act<Type> {
type Output = Type;
type Residual = Break;
fn from_output(output: Self::Output) -> Self {return unsafe {transmute(Some(output))}}
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {return match self.into() {
None => ControlFlow::Break(Break),
Some(value) => ControlFlow::Continue(value)
}}
}