Skip to main content

SpectrumSource

Trait SpectrumSource 

Source
pub trait SpectrumSource {
    // Required methods
    fn run_metadata(&self) -> RunMetadata;
    fn iter_spectra<'a>(
        &'a mut self,
    ) -> Box<dyn Iterator<Item = SpectrumRecord> + 'a>;

    // Provided methods
    fn iter_chromatograms<'a>(
        &'a mut self,
    ) -> Box<dyn Iterator<Item = ChromatogramRecord> + 'a> { ... }
    fn spectrum_count_hint(&self) -> Option<usize> { ... }
}
Expand description

A source of decoded mass spectra.

Vendors implement this on whatever value carries their open file state (e.g. RawFileReader + a &mut Read+Seek source for opentfraw, a Reader for opentimstdf).

The trait deliberately uses boxed iterators rather than RPITIT so that implementations can pick a different underlying iterator type per call without leaking that into the trait signature, and so consumers can hold a &mut dyn SpectrumSource for downstream plumbing (mzML writer, ingest pipelines, language bindings).

Required Methods§

Source

fn run_metadata(&self) -> RunMetadata

Run-level metadata. Cheap to call; vendors typically build this once.

Source

fn iter_spectra<'a>( &'a mut self, ) -> Box<dyn Iterator<Item = SpectrumRecord> + 'a>

Iterate every spectrum the file contains. Spectra the parser cannot decode should be skipped silently; the writer trusts whatever the iterator yields.

The iterator borrows self mutably so vendors can stream from disk without buffering the whole run in memory.

Provided Methods§

Source

fn iter_chromatograms<'a>( &'a mut self, ) -> Box<dyn Iterator<Item = ChromatogramRecord> + 'a>

Iterate chromatogram traces (TIC, BPC, SRM). Defaults to an empty iterator; most parsers do not synthesize chromatograms.

Source

fn spectrum_count_hint(&self) -> Option<usize>

Total number of spectra the source will yield, when known cheaply. Used by the mzML writer to populate <spectrumList count="...">. If None, the writer falls back to buffering spectrum offsets and patching the count at the end.

Implementors§