diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/lib.rs | 17 |
2 files changed, 19 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f9e6e4d5..8b2e9b5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#968](https://github.com/nix-rust/nix/pull/968)) - Added `unistd::execvpe` for Haiku, Linux and OpenBSD ([#975](https://github.com/nix-rust/nix/pull/975)) +- Added `Error::as_errno`. + ([#977](https://github.com/nix-rust/nix/pull/977)) ### Changed - Increased required Rust version to 1.24.1 @@ -110,6 +110,23 @@ pub enum Error { } impl Error { + /// Convert this `Error` to an [`Errno`](enum.Errno.html). + /// + /// # Example + /// + /// ``` + /// # use nix::Error; + /// # use nix::errno::Errno; + /// let e = Error::from(Errno::EPERM); + /// assert_eq!(Some(Errno::EPERM), e.as_errno()); + /// ``` + pub fn as_errno(&self) -> Option<Errno> { + if let &Error::Sys(ref e) = self { + Some(*e) + } else { + None + } + } /// Create a nix Error from a given errno pub fn from_errno(errno: Errno) -> Error { |