Nix/nix-rust/src/error.rs

32 lines
707 B
Rust
Raw Normal View History

2019-09-10 21:55:32 +02:00
#[derive(Debug)]
pub enum Error {
IOError(std::io::Error),
2019-09-10 21:55:32 +02:00
Misc(String),
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" {
2019-09-11 12:44:31 +02:00
#[allow(improper_ctypes)] // YOLO
fn make_error(s: &str) -> CppException;
2019-09-10 21:55:32 +02:00
}