Skip to main content

rsynko_memory/
selection.rs

1use crate::{Format, FormatPredicate, FormatSelection, InfoRecord, InfoValue, interpret_selection, predicate_accepts};
2use rsynko_media::{FormatPredicateMatchAlg, FormatSelectionApplyAlg, FormatViewAlg, MediaSorts};
3
4/// Interprets format predicates and selection programs over the reified media sorts.
5#[derive(Clone, Copy, Debug, Default)]
6pub struct ReferenceFormatSelector;
7
8impl MediaSorts for ReferenceFormatSelector {
9    type Value = InfoValue;
10    type Metadata = InfoRecord;
11    type Format = Format;
12    type Artifact = ();
13    type Media = ();
14    type Extraction = ();
15    type Extractor = ();
16    type Predicate = FormatPredicate;
17    type Selection = FormatSelection;
18    type Output = ();
19}
20
21impl FormatViewAlg for ReferenceFormatSelector {
22    fn format_text<'a>(&self, format: &'a Format, key: &str) -> Option<&'a str> {
23        format.text(key)
24    }
25}
26
27impl FormatPredicateMatchAlg for ReferenceFormatSelector {
28    fn format_matches(&self, predicate: &FormatPredicate, format: &Format) -> bool {
29        predicate_accepts(predicate, format)
30    }
31}
32
33impl FormatSelectionApplyAlg for ReferenceFormatSelector {
34    fn select_formats<'a>(&self, formats: &'a [Format], selection: &FormatSelection) -> Option<Vec<&'a Format>> {
35        interpret_selection(self, formats, selection)
36    }
37}