Removed expect

This commit is contained in:
Andrew Kane
2021-10-17 11:59:19 -07:00
parent 00a924922d
commit 241a52a100
2 changed files with 10 additions and 2 deletions

View File

@@ -1,6 +1,14 @@
use std::ffi::NulError;
#[derive(Debug)]
pub enum Error {
Io,
Parameter(String),
Unknown
}
impl From<NulError> for Error {
fn from(_err: NulError) -> Error {
Error::Io
}
}

View File

@@ -12,7 +12,7 @@ impl Model {
}
pub fn load(path: &str) -> Result<Self, Error> {
let cpath = CString::new(path).expect("CString::new failed");
let cpath = CString::new(path)?;
let model = unsafe { mf_load_model(cpath.as_ptr()) };
if model.is_null() {
return Err(Error::Io);
@@ -25,7 +25,7 @@ impl Model {
}
pub fn save(&self, path: &str) -> Result<(), Error> {
let cpath = CString::new(path).expect("CString::new failed");
let cpath = CString::new(path)?;
let status = unsafe { mf_save_model(self.model, cpath.as_ptr()) };
if status != 0 {
return Err(Error::Io);