@@ -299,6 +299,38 @@ pub enum Signal {
299
299
SigTrap = SIGTRAP ,
300
300
}
301
301
302
+ impl TryFrom < & str > for Signal {
303
+ type Error = Error ;
304
+
305
+ fn try_from ( value : & str ) -> Result < Self , Self :: Error > {
306
+ Ok ( match value {
307
+ "SIGABRT" => Signal :: SigAbort ,
308
+ "SIGBUS" => Signal :: SigBus ,
309
+ "SIGFPE" => Signal :: SigFloatingPointException ,
310
+ "SIGILL" => Signal :: SigIllegalInstruction ,
311
+ "SIGPIPE" => Signal :: SigPipe ,
312
+ "SIGSEGV" => Signal :: SigSegmentationFault ,
313
+ "SIGUSR2" => Signal :: SigUser2 ,
314
+ "SIGALRM" => Signal :: SigAlarm ,
315
+ "SIGHUP" => Signal :: SigHangUp ,
316
+ "SIGKILL" => Signal :: SigKill ,
317
+ "SIGQUIT" => Signal :: SigQuit ,
318
+ "SIGTERM" => Signal :: SigTerm ,
319
+ "SIGINT" => Signal :: SigInterrupt ,
320
+ "SIGTRAP" => Signal :: SigTrap ,
321
+ _ => return Err ( Error :: illegal_argument ( format ! ( "No signal named {value}" ) ) ) ,
322
+ } )
323
+ }
324
+ }
325
+
326
+ #[ cfg( feature = "std" ) ]
327
+ impl From < Signal > for nix:: sys:: signal:: Signal {
328
+ fn from ( value : Signal ) -> Self {
329
+ // we can be semi-certain that all signals exist in nix.
330
+ i32:: from ( value) . try_into ( ) . unwrap ( )
331
+ }
332
+ }
333
+
302
334
/// A list of crashing signals
303
335
pub static CRASH_SIGNALS : & [ Signal ] = & [
304
336
Signal :: SigAbort ,
0 commit comments