Skip to main content

dope_runtime/process/
shutdown.rs

1use std::{mem, os::fd};
2
3use crate::process::{gate, 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
23impl fd::AsFd for Shutdown<'_> {
24    fn as_fd(&self) -> fd::BorrowedFd<'_> {
25        self.source.as_fd()
26    }
27}
28
29impl crate::executor::Startup for Shutdown<'_> {
30    fn installed(&self) -> Result<(), crate::executor::InstallError> {
31        self.source.installed().map_err(Into::into)
32    }
33}
34
35const _: () = {
36    assert!(mem::size_of::<Shutdown<'static>>() == mem::size_of::<bus::Tx<'static>>());
37    assert!(mem::align_of::<Shutdown<'static>>() == mem::align_of::<bus::Tx<'static>>());
38};