myc

Self-custodial remote signer for Radroots apps
git clone https://radroots.dev/git/myc.git
Log | Files | Refs | README | LICENSE

runtime_signal.rs (1387B)


      1 //! Binary-owned process-signal injection for the Myc daemon.
      2 
      3 use core::{fmt, future::Future, pin::Pin};
      4 
      5 /// One normalized process signal supplied by the Myc binary.
      6 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
      7 pub enum MycProcessSignal {
      8     Interrupt,
      9     #[cfg(unix)]
     10     Terminate,
     11 }
     12 
     13 impl MycProcessSignal {
     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 MycProcessSignal {
     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 MycProcessSignalFuture<'a> =
     32     Pin<Box<dyn Future<Output = Option<MycProcessSignal>> + Send + 'a>>;
     33 
     34 /// Process-signal source installed only by the executable boundary.
     35 pub trait MycProcessSignalSource: Send {
     36     fn next_signal(&mut self) -> MycProcessSignalFuture<'_>;
     37 }
     38 
     39 #[cfg(test)]
     40 mod tests {
     41     use super::*;
     42 
     43     #[test]
     44     fn normalized_signal_names_are_stable() {
     45         assert_eq!(MycProcessSignal::Interrupt.as_str(), "interrupt");
     46         assert_eq!(MycProcessSignal::Interrupt.to_string(), "interrupt");
     47         #[cfg(unix)]
     48         assert_eq!(MycProcessSignal::Terminate.as_str(), "terminate");
     49     }
     50 }