Macro mzdata::mz_read

source ·
macro_rules! mz_read {
    ($source:expr, $reader:ident => $impl:tt) => { ... };
    ($source:expr, $reader:ident => $impl:tt, $C:ty, $D:ty) => { ... };
}
Expand description

A macro that dynamically works out how to get a SpectrumSource-derived object from a path or io::Read + io::Seek boxed object. This is meant to be a convenience for working with a scoped file reader without penalty.

$source is coerced into a Source which the macro in turn probes to determine the appropriate file reading type. This lets you interact with the concrete type intersection without concern with object safety in an anonymous closure:

let spectra: Vec<Spectrum> = mzdata::mz_read!("./test/data/small.mzML".as_ref(), reader => { reader.collect() })?;

The closure will return a std::io::Result whose success value is inferred from context. The reader’s lifetime is bound to the closure, and cannot be extracted without substantial type system torture.

If you want to use peak types other than the simple defaults, pass them as additional parameters after the closure.