asimov_patterns/programs/
reader.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/// RDF dataset importer. Consumes some input, produces RDF output.
8///
9/// See: https://asimov-specs.github.io/program-patterns/#reader
10pub trait Reader<T, E>: Execute<T, E> {}
11
12/// Configuration options for [`Reader`].
13///
14/// # Examples
15///
16/// ```rust
17/// use asimov_patterns::ReaderOptions;
18///
19/// let options = ReaderOptions::builder()
20///     .input("jsonld")
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 ReaderOptions {
27    /// Extended nonstandard reader options.
28    #[builder(field)]
29    pub other: Vec<String>,
30
31    /// The input format.
32    pub input: Option<String>,
33
34    /// The output format.
35    pub output: Option<String>,
36}
37
38impl<S: reader_options_builder::State> ReaderOptionsBuilder<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}