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