runtime_signal.rs (1387B)
1 //! Binary-owned process-signal injection for the Rhi daemon. 2 3 use core::{fmt, future::Future, pin::Pin}; 4 5 /// One normalized process signal supplied by the Rhi binary. 6 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 7 pub enum RhiProcessSignal { 8 Interrupt, 9 #[cfg(unix)] 10 Terminate, 11 } 12 13 impl RhiProcessSignal { 14 #[must_use] 15 pub const fn as_str(self) -> &'static str { 16 match self { 17 Self::Interrupt => "interrupt", 18 #[cfg(unix)] 19 Self::Terminate => "terminate", 20 } 21 } 22 } 23 24 impl fmt::Display for RhiProcessSignal { 25 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { 26 formatter.write_str(self.as_str()) 27 } 28 } 29 30 /// Boxed wait returned by a binary-owned signal source. 31 pub type RhiProcessSignalFuture<'a> = 32 Pin<Box<dyn Future<Output = Option<RhiProcessSignal>> + Send + 'a>>; 33 34 /// Process-signal source installed only by the executable boundary. 35 pub trait RhiProcessSignalSource: Send { 36 fn next_signal(&mut self) -> RhiProcessSignalFuture<'_>; 37 } 38 39 #[cfg(test)] 40 mod tests { 41 use super::*; 42 43 #[test] 44 fn normalized_signal_names_are_stable() { 45 assert_eq!(RhiProcessSignal::Interrupt.as_str(), "interrupt"); 46 assert_eq!(RhiProcessSignal::Interrupt.to_string(), "interrupt"); 47 #[cfg(unix)] 48 assert_eq!(RhiProcessSignal::Terminate.as_str(), "terminate"); 49 } 50 }