Skip to content

Instantly share code, notes, and snippets.

@Enet4
Last active April 11, 2018 22:46
Show Gist options
  • Save Enet4/209bce64ed8174598a1c584c92e95554 to your computer and use it in GitHub Desktop.
Save Enet4/209bce64ed8174598a1c584c92e95554 to your computer and use it in GitHub Desktop.
error.rs at faiss-rs
#[derive(Debug, Clone, PartialEq)]
pub struct NativeError {
code: c_int,
msg: String,
}
impl NativeError {
pub fn from_last_error(code: c_int) -> Self {
unsafe {
let e: *const _ = faiss_get_last_error();
assert!(!e.is_null());
let cstr = CStr::from_ptr(e);
let msg: String = cstr.to_string_lossy().into_owned();
NativeError { code, msg }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment