Skip to content

Commit

Permalink
Renamed MightBeSingle to SingleOrVec
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarEclipse363 committed May 30, 2024
1 parent c6fea66 commit ff92ecd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions components/config/src/config/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<String>,
pub taxonomies: Vec<taxonomies::TaxonomyConfig>,
/// Whether to generate search index for that language, defaults to `false`
Expand Down
18 changes: 9 additions & 9 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct Config {
pub feed_limit: Option<usize>,
/// 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<String>,
/// If set, files from static/ will be hardlinked instead of copied to the output dir.
pub hard_link_static: bool,
Expand Down Expand Up @@ -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<Vec<T>, D::Error>
pub(crate) fn single_or_vec<'de, T, D>(deserializer: D) -> Result<Vec<T>, 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<T> {
pub(crate) enum SingleOrVec<T> {
Multiple(Vec<T>),
One(T),
None,
}

impl<T> From<MightBeSingle<T>> for Vec<T> {
fn from(x: MightBeSingle<T>) -> Vec<T> {
use MightBeSingle::*;
impl<T> From<SingleOrVec<T>> for Vec<T> {
fn from(x: SingleOrVec<T>) -> Vec<T> {
use SingleOrVec::*;

match x {
Multiple(v) => v,
Expand All @@ -430,13 +430,13 @@ impl<T> From<MightBeSingle<T>> for Vec<T> {
}
}

impl<T> From<Vec<T>> for MightBeSingle<T> {
impl<T> From<Vec<T>> for SingleOrVec<T> {
fn from(value: Vec<T>) -> Self {
Self::Multiple(value)
}
}

impl<T> Default for MightBeSingle<T> {
impl<T> Default for SingleOrVec<T> {
fn default() -> Self {
Self::None
}
Expand Down

0 comments on commit ff92ecd

Please sign in to comment.