use std::borrow::Cow;
#[derive(Debug, Clone, thiserror::Error)]
#[error("{0}")]
pub struct LibraryError(Cow<'static, str>);
pub(crate) fn check_cuvs(status: ffi::cuvsError_t) -> Result<(), LibraryError> {
match status {
ffi::cuvsError_t::CUVS_SUCCESS => Ok(()),
_ => {
let text: Cow<'static, str> = unsafe {
let text_ptr = ffi::cuvsGetLastErrorText();
if text_ptr.is_null() {
Cow::Borrowed("unknown cuVS error")
} else {
let cstr = std::ffi::CStr::from_ptr(text_ptr);
Cow::Owned(String::from_utf8_lossy(cstr.to_bytes()).into_owned())
}
};
Err(LibraryError(text))
}
}
}