summaryrefslogtreecommitdiff
path: root/src/sys/signal.rs
diff options
context:
space:
mode:
authorMikail Bagishov <bagishov.mikail@yandex.ru>2019-10-16 20:04:11 +0300
committerMikail Bagishov <bagishov.mikail@yandex.ru>2019-10-29 17:37:48 +0300
commitbacb85ecd958bbf4ca013d900dd33562e7102f56 (patch)
treee7496fba87302ec880f2525f3bad703d842b5b8a /src/sys/signal.rs
parenta04fe5946872b0cb6d61e22f4822797011ba9b53 (diff)
downloadnix-bacb85ecd958bbf4ca013d900dd33562e7102f56.zip
Implement Signal::as_str()
Diffstat (limited to 'src/sys/signal.rs')
-rw-r--r--src/sys/signal.rs17
1 files changed, 14 insertions, 3 deletions
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<str> for Signal {
- fn as_ref(&self) -> &str {
- match *self {
+impl Signal {
+ /// Returns name of signal.
+ ///
+ /// This function is equivalent to `<Signal as AsRef<str>>::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<str> for Signal {
}
}
+impl AsRef<str> 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())