pub trait Missing<T> {
// Required method
fn error_if_missing(
self,
id: &'static str,
msg: &'static str,
) -> Result<T, MissingVariable>
where Self: Sized;
}Expand description
One of the first things a MEX file has to do is parse its arguments — the LHS array.
Part of that is checking whether it got all the arguments it expected. In MEX files,
this is best done via slice’s .get() method. This method then returns an Option;
Some if there is an argument, None if that slot is out of bounds. The value can then
be pattern matched out via a let val = if let Some(_), but that requires an else
arm and is overall just combersome.
This trait is the solution for that problem. It elegantly maps an Option to a
Result; an Ok if there was some value, an Err with a MissingVariable
MexMessage if not.
Note that there is a slight difference in functionality between the two implementers.
Required Methods§
fn error_if_missing(
self,
id: &'static str,
msg: &'static str,
) -> Result<T, MissingVariable>where
Self: Sized,
Implementations on Foreign Types§
Source§impl<'a> Missing<&'a mxArray_tag> for Option<&&'a mxArray>
impl<'a> Missing<&'a mxArray_tag> for Option<&&'a mxArray>
Best used with get on a slice.
fn error_if_missing( self, id: &'static str, msg: &'static str, ) -> Result<&'a mxArray, MissingVariable>
Source§impl<'s> Missing<&'s mut Option<MxArray>> for Option<&'s mut Option<MxArray>>
impl<'s> Missing<&'s mut Option<MxArray>> for Option<&'s mut Option<MxArray>>
Best used with get_mut on a slice, and replace on the reference yielded to place
the new value.