Skip to main content

dope_runtime/process/
terminal.rs

1use std::mem;
2
3use crate::{
4    process::{self, failure::bus, runtime::bus::Tx},
5    shutdown,
6};
7
8/// Consumes a shutdown result at the final worker failure boundary.
9pub struct Terminal<'run> {
10    pub(in crate::process) source: Tx<'run>,
11}
12
13impl<'run> Terminal<'run> {
14    pub fn fail(self) -> Result<bus::Event, bus::Fault> {
15        match self.source.report() {
16            bus::Report::Clean => Ok(bus::Event::Failed),
17            bus::Report::Failed(cause) => Err(cause),
18        }
19    }
20
21    pub fn finish(
22        self,
23        result: shutdown::Requested<process::Shutdown<'run>>,
24    ) -> Result<bus::Event, bus::Fault> {
25        result.terminal(self.source.report())
26    }
27}
28
29impl<'run> shutdown::Requested<process::Shutdown<'run>> {
30    pub(crate) fn terminal(self, report: bus::Report) -> Result<bus::Event, bus::Fault> {
31        match report {
32            bus::Report::Clean => Ok(bus::Event::Done),
33            bus::Report::Failed(failure) => Err(failure),
34        }
35    }
36}
37
38const _: () = {
39    assert!(mem::size_of::<shutdown::Requested<process::Shutdown<'static>>>() == 0);
40    assert!(mem::size_of::<Terminal<'static>>() == mem::size_of::<usize>());
41    assert!(mem::align_of::<Terminal<'static>>() == mem::align_of::<usize>());
42    assert!(mem::size_of::<Option<Terminal<'static>>>() == mem::size_of::<usize>());
43};