Skip to content

Commit

Permalink
Implement Signal::as_str()
Browse files Browse the repository at this point in the history
  • Loading branch information
MikailBag committed Oct 29, 2019
1 parent a04fe59 commit bacb85e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
17 changes: 14 additions & 3 deletions src/sys/signal.rs
Expand Up @@ -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",
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit bacb85e

Please sign in to comment.