From bacb85ecd958bbf4ca013d900dd33562e7102f56 Mon Sep 17 00:00:00 2001 From: Mikail Bagishov Date: Wed, 16 Oct 2019 20:04:11 +0300 Subject: Implement Signal::as_str() --- src/sys/signal.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/sys') diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 1224888e..b746b3d4 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -112,9 +112,14 @@ impl FromStr for Signal { } } -impl AsRef for Signal { - fn as_ref(&self) -> &str { - match *self { +impl Signal { + /// Returns name of signal. + /// + /// This function is equivalent to `>::as_ref()`, + /// with difference that returned string is `'static` + /// and not bound to `self`'s lifetime. + pub fn as_str(self) -> &'static str { + match self { Signal::SIGHUP => "SIGHUP", Signal::SIGINT => "SIGINT", Signal::SIGQUIT => "SIGQUIT", @@ -157,6 +162,12 @@ impl AsRef for Signal { } } +impl AsRef for Signal { + fn as_ref(&self) -> &str { + self.as_str() + } +} + impl fmt::Display for Signal { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str(self.as_ref()) -- cgit v1.2.3