diff --git a/CHANGELOG.md b/CHANGELOG.md index fa18a42960..7d58a270d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate ### Added +- Added `Signal::as_str()`: returns signal name as `&'static str` + (#[1138](https://github.com/nix-rust/nix/pull/1138)) - Added `posix_fallocate`. ([#1105](https://github.com/nix-rust/nix/pull/1105)) diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 1224888ea3..b746b3d4d2 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())