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;
6
7/// Graph iterator. Takes a URL input, produces RDF output.
8///
9/// See: https://asimov-specs.github.io/program-patterns/#cataloger
10pub trait Cataloger<T, E>: Execute<T, E> {}
11
12/// Configuration options for [`Cataloger`].
13///
14/// # Examples
15///
16/// ```rust
17/// use asimov_patterns::CatalogerOptions;
18///
19/// let options = CatalogerOptions::builder()
20///     .limit(100)
21///     .output("jsonld")
22///     .build();
23/// ```
24#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Builder)]
25#[builder(derive(Debug), on(String, into))]
26pub struct CatalogerOptions {
27    /// Extended nonstandard cataloger options.
28    #[builder(field)]
29    pub other: Vec<String>,
30
31    /// The maximum number of outputs.
32    pub limit: Option<usize>,
33
34    /// The output format.
35    pub output: Option<String>,
36}
37
38impl<S: cataloger_options_builder::State> CatalogerOptionsBuilder<S> {
39    pub fn other(mut self, flag: impl Into<String>) -> Self {
40        self.other.push(flag.into());
41        self
42    }
43
44    pub fn maybe_other(mut self, flag: Option<impl Into<String>>) -> Self {
45        if let Some(flag) = flag {
46            self.other.push(flag.into());
47        }
48        self
49    }
50}