diff --git a/src/types.rs b/src/types.rs index eb9173b92fb182e810374f805b514d241c803926..04b28f957757b53aca23525be2a918372105cd16 100644 --- a/src/types.rs +++ b/src/types.rs @@ -42,6 +42,18 @@ impl IntoRustType<f64> for MxArray { } } +impl IntoRustType<f32> for MxArray { + fn into_rust(self) -> SResult<f32> { + let out = Numeric::<f32, _>::from_mx_array(self) + .mexerr(Error::InvalidMatlabType("cast to a single instead".into()))? + .data() + .first() + .mexerr(Error::Parse)? + .to_owned(); + Ok(out) + } +} + impl IntoRustType<Vec<f64>> for MxArray { fn into_rust(self) -> SResult<Vec<f64>> { let out = Numeric::<f64, _>::from_mx_array(self) @@ -69,6 +81,16 @@ impl IntoMatlabType for Vec<f64> { } } +impl IntoMatlabType for Vec<f32> { + fn into_matlab(self) -> SResult<MxArray> { + let len = self.len(); + Ok(Numeric::<f32, _>::new(self.into_boxed_slice(), &[len]) + .unwrap() + .deref() + .to_owned()) + } +} + /// Functions available to the user #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Mode {