Advanced topics

Bulk decoding of metadata

To populate a Vec with decoded metadata and accounting for some rows not having metadata:

  • Realize that the decode methods of the MetadataRoundtrip trait are associated functions.
  • We can use a lending iterator over rows to avoid unnecessary copying.

Therefore:

    let mut mutation_row_lending_iterator = tables.mutations().lending_iter();
    let mut decoded_md = vec![];
    while let Some(row_view) = mutation_row_lending_iterator.next() {
        match row_view.metadata {
            Some(slice) => decoded_md.push(Some(MutationMetadata::decode(slice).unwrap())),
            None => decoded_md.push(None),
        }
    }

To filter out rows without metadata:

    let mut mutation_row_lending_iterator = tables.mutations().lending_iter();
    let mut decoded_md = vec![];
    while let Some(row_view) = mutation_row_lending_iterator
        .next()
        .filter(|rv| rv.metadata.is_some())
    {
        decoded_md.push((
            row_view.id,
            // The unwrap will never panic because of our filter
            MutationMetadata::decode(row_view.metadata.unwrap()).unwrap(),
        ));
    }

The first method gives `Vec<Option<M