mirror of
https://github.com/dnlbauer/xdrfile.git
synced 2026-09-10 22:25:30 +00:00
Streamlined error generation
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user