Missing

Trait Missing 

Source
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§

Source

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>

See Missing for the main explanation. This implementation also dereferences the indirection of the slice, yielding a direct reference to the mxArray.

Best used with get on a slice.

Source§

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>>

See Missing for the main explanation. Contrast with the implementation for Option<&&mxArray>. This implementation does not dereference the slice’s reference, since MxArray does not implement copy —­The slice remains the owner of the MxArray.

Best used with get_mut on a slice, and replace on the reference yielded to place the new value.

Source§

fn error_if_missing( self, id: &'static str, msg: &'static str, ) -> Result<&'s mut Option<MxArray>, MissingVariable>

Implementors§