Skip to main content

libutils_report/
act.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> CORE
6use core::marker::Destruct;
7
8//> HEAD -> STD
9use std::process::{
10    ExitCode,
11    Termination
12};
13
14
15//^
16//^ ACT
17//^
18
19//> ACT -> STRUCT
20pub struct Act<Type> {
21    option: Option<Type>
22}
23
24//> ACT -> TERMINATION
25impl Termination for Act<()> {
26    fn report(self) -> ExitCode {return match self.option {
27        None => ExitCode::FAILURE,
28        Some(()) => ExitCode::SUCCESS
29    }}
30}
31
32//> ACT -> IMPLEMENTATION
33const impl<Type: [const] Destruct> Act<Type> {
34    #[inline]
35    pub fn map<Return, Closure: [const] FnOnce(Type) -> Return + [const] Destruct>(self, closure: Closure) -> Act<Return> {return Act {
36        option: self.option.map(closure)
37    }}
38    #[inline]
39    pub fn value(self) -> Option<Type> {return self.option}
40}