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)] #[derive(Debug)]
pub enum Error { pub enum Error {
Io, Io,
Parameter(String), Parameter(String),
Unknown 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> { 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()) }; let model = unsafe { mf_load_model(cpath.as_ptr()) };
if model.is_null() { if model.is_null() {
return Err(Error::Io); return Err(Error::Io);
@@ -25,7 +25,7 @@ impl Model {
} }
pub fn save(&self, path: &str) -> Result<(), Error> { 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()) }; let status = unsafe { mf_save_model(self.model, cpath.as_ptr()) };
if status != 0 { if status != 0 {
return Err(Error::Io); return Err(Error::Io);