From df8ba875167e2a95b801e7929c167f8016ffa9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 22 Oct 2022 17:20:57 +0300 Subject: [PATCH] feat: add more implementations for converting `nix::Error` --- src/uucore/src/lib/mods/error.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index 7377c021b..67fed9a46 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -519,6 +519,31 @@ impl FromIo> for Result { } } +impl FromIo> for nix::Error { + fn map_err_context(self, context: impl FnOnce() -> String) -> UResult { + Err(Box::new(UIoError { + context: Some((context)()), + inner: std::io::Error::from_raw_os_error(self as i32), + }) as Box) + } +} + +impl From for UIoError { + fn from(f: nix::Error) -> Self { + Self { + context: None, + inner: std::io::Error::from_raw_os_error(f as i32), + } + } +} + +impl From for Box { + fn from(f: nix::Error) -> Self { + let u_error: UIoError = f.into(); + Box::new(u_error) as Self + } +} + /// Shorthand to construct [`UIoError`]-instances. /// /// This macro serves as a convenience call to quickly construct instances of