asimov_patterns/programs/
resolver.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/// URI resolver. Takes a URI (that is, URN or URL) input, produces a resolved URL output.
8///
9/// See: https://asimov-specs.github.io/program-patterns/#resolver
10pub trait Resolver<T, E>: Execute<T, E> {}
11
12/// Configuration options for [`Resolver`].
13///
14/// # Examples
15///
16/// ```rust
17/// use asimov_patterns::ResolverOptions;
18///
19/// let options = ResolverOptions::builder()
20///     .limit(100)
21///     .build();
22/// ```
23#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Builder)]
24#[builder(derive(Debug), on(String, into))]
25pub struct ResolverOptions {
26    /// Extended nonstandard resolver options.
27    #[builder(field)]
28    pub other: Vec<String>,
29
30    /// The maximum number of outputs.
31    pub limit: Option<usize>,
32}
33
34impl<S: resolver_options_builder::State> ResolverOptionsBuilder<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}