#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Options {
pub(crate) lang: Option<String>,
pub(crate) fields: Option<Vec<String>>,
pub(crate) security: Option<bool>,
pub(crate) rate: Option<bool>,
}
impl Options {
pub fn new() -> Self {
Self::default()
}
pub fn with_lang(mut self, lang: impl Into<String>) -> Self {
self.lang = Some(lang.into());
self
}
pub fn with_fields<I, S>(mut self, fields: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.fields = Some(fields.into_iter().map(Into::into).collect());
self
}
pub fn with_security(mut self, enabled: bool) -> Self {
self.security = Some(enabled);
self
}
pub fn with_rate(mut self, enabled: bool) -> Self {
self.rate = Some(enabled);
self
}
pub(crate) fn merged_with(&self, other: &Options) -> Options {
Options {
lang: other.lang.clone().or_else(|| self.lang.clone()),
fields: other.fields.clone().or_else(|| self.fields.clone()),
security: other.security.or(self.security),
rate: other.rate.or(self.rate),
}
}
}