Removed expect
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user