diff options
Diffstat (limited to 'nix-rust/src/error.rs')
-rw-r--r-- | nix-rust/src/error.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/nix-rust/src/error.rs b/nix-rust/src/error.rs index 28d0abdef..a2003be6f 100644 --- a/nix-rust/src/error.rs +++ b/nix-rust/src/error.rs @@ -1,5 +1,30 @@ #[derive(Debug)] pub enum Error { + IOError(std::io::Error), Misc(String), - Foreign(libc::c_void), // == std::exception_ptr + Foreign(CppException), +} + +impl From<std::io::Error> for Error { + fn from(err: std::io::Error) -> Self { + Error::IOError(err) + } +} + +impl From<Error> for CppException { + fn from(err: Error) -> Self { + match err { + Error::Foreign(ex) => ex, + Error::Misc(s) => unsafe { make_error(&s) }, + Error::IOError(err) => unsafe { make_error(&err.to_string()) }, + } + } +} + +#[repr(C)] +#[derive(Debug)] +pub struct CppException(*const libc::c_void); // == std::exception_ptr* + +extern "C" { + fn make_error(s: &str) -> CppException; } |