Skip to main content

dope_runtime/process/
shutdown.rs

1use std::{mem, os::fd};
2
3use crate::process::{gate, lifecycle, runtime::bus};
4
5/// Shutdown source borrowed from the exact process run that owns this worker.
6///
7/// A proof issued by the standalone shutdown API cannot be retagged as a
8/// production process proof.
9pub struct Shutdown<'run> {
10    pub(in crate::process) source: bus::Tx<'run>,
11}
12
13impl<'run> Shutdown<'run> {
14    pub(super) const fn new(tx: bus::Tx<'run>) -> Self {
15        Self { source: tx }
16    }
17
18    pub(super) fn gate(&self) -> gate::Closed<'run> {
19        gate::Closed::new(self.source)
20    }
21
22    pub fn control(&self) -> lifecycle::Control<'_> {
23        lifecycle::Control::new(self.source.as_fd())
24    }
25
26    pub fn terminal(&self) -> crate::process::Terminal<'run> {
27        crate::process::Terminal {
28            source: self.source,
29        }
30    }
31}
32
33impl fd::AsFd for Shutdown<'_> {
34    fn as_fd(&self) -> fd::BorrowedFd<'_> {
35        self.source.as_fd()
36    }
37}
38
39impl crate::executor::Startup for Shutdown<'_> {
40    fn installed(&self) -> Result<(), crate::executor::InstallError> {
41        self.source.installed().map_err(Into::into)
42    }
43}
44
45const _: () = {
46    assert!(mem::size_of::<Shutdown<'static>>() == mem::size_of::<bus::Tx<'static>>());
47    assert!(mem::align_of::<Shutdown<'static>>() == mem::align_of::<bus::Tx<'static>>());
48};