Streamlined error generation

This commit is contained in:
Josh Mitchell
2020-11-08 00:17:37 +11:00
parent 36a722e721
commit 95b1bdba57
2 changed files with 22 additions and 36 deletions

View File

@@ -115,7 +115,7 @@ impl std::error::Error for Error {
}
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum ErrorCode {
ExdrOk,
ExdrHeader,
@@ -141,6 +141,15 @@ impl ErrorCode {
_ => false,
}
}
pub fn check<T>(code: impl Into<Self>, value: T) -> std::result::Result<T, Self> {
let code = code.into();
if let Self::ExdrOk = code {
Ok(value)
} else {
Err(code)
}
}
}
impl From<c_abi::xdrfile::BindgenTy1> for ErrorCode {