asimov_patterns/programs/
writer.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 exporter. Consumes RDF input, produces some output.
8///
9/// See: https://asimov-specs.github.io/program-patterns/#writer
10pub trait Writer<T, E>: Execute<T, E> {}
11
12/// Configuration options for [`Writer`].
13///
14/// # Examples
15///
16/// ```rust
17/// use asimov_patterns::WriterOptions;
18///
19/// let options = WriterOptions::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 WriterOptions {
27    /// Extended nonstandard writer 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: writer_options_builder::State> WriterOptionsBuilder<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}