diff --git a/components/config/src/config/languages.rs b/components/config/src/config/languages.rs index b6588bee7f..1d7f3816da 100644 --- a/components/config/src/config/languages.rs +++ b/components/config/src/config/languages.rs @@ -4,8 +4,8 @@ use errors::{bail, Result}; use libs::unic_langid::LanguageIdentifier; use serde::{Deserialize, Serialize}; -use crate::config::might_be_single; use crate::config::search; +use crate::config::single_or_vec; use crate::config::taxonomies; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -20,7 +20,7 @@ pub struct LanguageOptions { pub generate_feeds: bool, /// The filenames to use for feeds. Used to find the templates, too. /// Defaults to ["atom.xml"], with "rss.xml" also having a template provided out of the box. - #[serde(alias = "feed_filename", deserialize_with = "might_be_single")] + #[serde(alias = "feed_filename", deserialize_with = "single_or_vec")] pub feed_filenames: Vec, pub taxonomies: Vec, /// Whether to generate search index for that language, defaults to `false` diff --git a/components/config/src/config/mod.rs b/components/config/src/config/mod.rs index 334bb945ed..bb9bb5bb71 100644 --- a/components/config/src/config/mod.rs +++ b/components/config/src/config/mod.rs @@ -57,7 +57,7 @@ pub struct Config { pub feed_limit: Option, /// The filenames to use for feeds. Used to find the templates, too. /// Defaults to ["atom.xml"], with "rss.xml" also having a template provided out of the box. - #[serde(alias = "feed_filename", deserialize_with = "might_be_single")] + #[serde(alias = "feed_filename", deserialize_with = "single_or_vec")] pub feed_filenames: Vec, /// If set, files from static/ will be hardlinked instead of copied to the output dir. pub hard_link_static: bool, @@ -401,26 +401,26 @@ impl Default for Config { } /// Used for deserializing values that can be either a single value or a vec of values -pub(crate) fn might_be_single<'de, T, D>(deserializer: D) -> Result, D::Error> +pub(crate) fn single_or_vec<'de, T, D>(deserializer: D) -> Result, D::Error> where T: DeserializeOwned, D: Deserializer<'de>, { - let v = MightBeSingle::deserialize(deserializer)?; + let v = SingleOrVec::deserialize(deserializer)?; Ok(v.into()) } #[derive(Debug, Clone, Deserialize, PartialEq, Eq)] #[serde(untagged)] -pub(crate) enum MightBeSingle { +pub(crate) enum SingleOrVec { Multiple(Vec), One(T), None, } -impl From> for Vec { - fn from(x: MightBeSingle) -> Vec { - use MightBeSingle::*; +impl From> for Vec { + fn from(x: SingleOrVec) -> Vec { + use SingleOrVec::*; match x { Multiple(v) => v, @@ -430,13 +430,13 @@ impl From> for Vec { } } -impl From> for MightBeSingle { +impl From> for SingleOrVec { fn from(value: Vec) -> Self { Self::Multiple(value) } } -impl Default for MightBeSingle { +impl Default for SingleOrVec { fn default() -> Self { Self::None }