asimov_patterns/programs/
fetcher.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/// URL resource materializer. Consumes a URL input, produces RDF output.
8///
9/// See: https://asimov-specs.github.io/program-patterns/#fetcher
10pub trait Fetcher<T, E>: Execute<T, E> {}
11
12/// Configuration options for [`Fetcher`].
13///
14/// # Examples
15///
16/// ```rust
17/// use asimov_patterns::FetcherOptions;
18///
19/// let options = FetcherOptions::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 FetcherOptions {
26    /// Extended nonstandard fetcher options.
27    #[builder(field)]
28    pub other: Vec<String>,
29
30    /// The output format.
31    pub output: Option<String>,
32}
33
34impl<S: fetcher_options_builder::State> FetcherOptionsBuilder<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}