Macro mzdata::mz_write

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

A macro that dynamically works out how to get a SpectrumWriter from a path or io::Write boxed object.

$sink is coerced to a Sink which in turn the macro probes in order to determine how to create the appropriate writer type. Unlike other uses of Sink, Sender and SyncSender are not supported. It lets you interact with the concrete type intersection in an anonymous closure:

    use mzdata::{mz_read, mz_write};
    mzdata::mz_read!("./test/data/small.mzML".as_ref(), reader => {
        mzdata::mz_write!("./tmp/test.mzML".as_ref(), writer => {
            writer.copy_metadata_from(&reader);
            for s in reader {
                writer.write_owned(s)?;
            }
        })?;
    })?;

The closure will return a std::io::Result whose success value is inferred from context. The writer’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