Skip to main content

asimov_patterns/programs/
cataloger.rs

1// This is free and unencumbered software released into the public domain.
2
3use crate::Execute;
4use alloc::{string::String, vec::Vec};
5use bon::Builder;
6use clientele::options::sort::SortKeys;
7
8/// Graph iterator. Takes a URL input, produces RDF output.
9///
10/// See: https://asimov-specs.github.io/program-patterns/#cataloger
11pub trait Cataloger<T, E>: Execute<T, E> {}
12
13/// Configuration options for [`Cataloger`].
14///
15/// # Examples
16///
17/// ```rust
18/// use asimov_patterns::CatalogerOptions;
19///
20/// let options = CatalogerOptions::builder()
21///     .limit(100)
22///     .output("jsonld")
23///     .build();
24/// ```
25#[derive(Clone, Debug, Default, Eq, Hash, /*Ord,*/ PartialEq, /*PartialOrd,*/ Builder)]
26#[builder(derive(Debug), on(String, into))]
27pub struct CatalogerOptions {
28    /// Extended nonstandard cataloger options.
29    #[builder(field)]
30    pub other: Vec<String>,
31
32    /// Sort resources by the specified keys. (Prefix a key with `-` for descending order.)
33    pub sort: Option<SortKeys>,
34
35    /// The index offset of the first output.
36    pub offset: Option<usize>,
37
38    /// The maximum count of outputs.
39    pub limit: Option<usize>,
40
41    /// The output format.
42    pub output: Option<String>,
43}
44
45impl<S: cataloger_options_builder::State> CatalogerOptionsBuilder<S> {
46    pub fn other(mut self, flag: impl Into<String>) -> Self {
47        self.other.push(flag.into());
48        self
49    }
50
51    pub fn maybe_other(mut self, flag: Option<impl Into<String>>) -> Self {
52        if let Some(flag) = flag {
53            self.other.push(flag.into());
54        }
55        self
56    }
57}