Skip to main content

libutils_report/
shortcut.rs

1//^ 
2//^ HEAD
3//^ 
4
5//> HEAD -> SUPER
6use super::act::Act;
7
8//> HEAD -> CORE
9use core::{
10    ops::{
11        FromResidual,
12        Residual,
13        Try,
14        ControlFlow
15    },
16    mem::transmute_neo as transmute,
17    marker::Destruct
18};
19
20
21//^
22//^ TYPES
23//^
24
25//> TYPES -> BREAK
26pub struct Break;
27
28
29//^
30//^ FROMRESIDUAL
31//^
32
33//> FROMRESIDUAL -> ACT
34const impl<Type> FromResidual<Break> for Act<Type> {
35    fn from_residual(_residual: Break) -> Self {return unsafe {transmute(None::<Type>)}}
36}
37
38
39//^
40//^ RESIDUAL
41//^
42
43//> RESIDUAL -> BREAK
44const impl<Type: [const] Destruct> Residual<Type> for Break {
45    type TryType = Act<Type>;
46}
47
48
49//^
50//^ TRY
51//^
52
53//> TRY -> ATTACHMENT
54const impl<Type: [const] Destruct> Try for Act<Type> {
55    type Output = Type;
56    type Residual = Break;
57    fn from_output(output: Self::Output) -> Self {return unsafe {transmute(Some(output))}}
58    fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {return if let Some(value) = self.value() {
59        ControlFlow::Continue(value)
60    } else {ControlFlow::Break(Break)}}
61}