Expose from_raw for Status
This commit is contained in:
parent
4d1f3edd5d
commit
be0e5eb9da
@ -16,7 +16,7 @@ macro_rules! call {
|
||||
// the checked call that returns Ok(res) on success
|
||||
($name:ident, $($arg:expr),* => $res:expr) => {{
|
||||
let status = call!(@raw $name, $($arg),*);
|
||||
match crate::Status::new(status) {
|
||||
match crate::Status::from_raw(status) {
|
||||
Some(status) => std::result::Result::Err(crate::Error::OrtError(status)),
|
||||
None => std::result::Result::Ok($res),
|
||||
}
|
||||
|
14
src/lib.rs
14
src/lib.rs
@ -90,19 +90,17 @@ impl From<ffi::NulError> for Error {
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
impl Status {
|
||||
fn new(raw: *mut sys::Status) -> Option<Status> {
|
||||
pub unsafe fn from_raw(raw: *mut sys::Status) -> Option<Status> {
|
||||
if raw.is_null() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let error_code = call!(@unsafe @raw GetErrorCode, raw);
|
||||
let error_msg = unsafe {
|
||||
CStr::from_ptr(call!(@raw GetErrorMessage, raw))
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
};
|
||||
let error_code = call!(@raw GetErrorCode, raw);
|
||||
let error_msg = CStr::from_ptr(call!(@raw GetErrorMessage, raw))
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
call!(@unsafe @raw ReleaseStatus, raw);
|
||||
call!(@raw ReleaseStatus, raw);
|
||||
|
||||
Some(Status {
|
||||
error_code,
|
||||
|
Loading…
Reference in New Issue
Block a user