add none configformat case to hide other errors

This commit is contained in:
Toshit Chawda 2024-09-01 20:48:11 -07:00
parent 23b96c2073
commit 9d1604cc3e
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D

View file

@ -339,6 +339,8 @@ impl Config {
ConfigFormat::Json => serde_json::to_string_pretty(self)?, ConfigFormat::Json => serde_json::to_string_pretty(self)?,
#[cfg(feature = "yaml")] #[cfg(feature = "yaml")]
ConfigFormat::Yaml => serde_yaml::to_string(self)?, ConfigFormat::Yaml => serde_yaml::to_string(self)?,
#[cfg(not(any(feature = "toml", feature = "json", feature = "yaml")))]
ConfigFormat::None => String::new(),
}) })
} }
@ -350,6 +352,8 @@ impl Config {
ConfigFormat::Json => serde_json::from_str(&string)?, ConfigFormat::Json => serde_json::from_str(&string)?,
#[cfg(feature = "yaml")] #[cfg(feature = "yaml")]
ConfigFormat::Yaml => serde_yaml::from_str(&string)?, ConfigFormat::Yaml => serde_yaml::from_str(&string)?,
#[cfg(not(any(feature = "toml", feature = "json", feature = "yaml")))]
ConfigFormat::None => { let _ = string; Self::default() },
}) })
} }
} }
@ -362,19 +366,22 @@ pub enum ConfigFormat {
Json, Json,
#[cfg(feature = "yaml")] #[cfg(feature = "yaml")]
Yaml, Yaml,
#[cfg(not(any(feature = "toml", feature = "json", feature = "yaml")))]
None,
} }
impl Default for ConfigFormat { impl Default for ConfigFormat {
fn default() -> Self { fn default() -> Self {
cfg_if! { cfg_if! {
if #[cfg(feature = "toml")] { if #[cfg(feature = "toml")] {
return Self::Toml; Self::Toml
} else if #[cfg(feature = "json")] { } else if #[cfg(feature = "json")] {
return Self::Json; Self::Json
} else if #[cfg(feature = "yaml")] { } else if #[cfg(feature = "yaml")] {
return Self::Yaml; Self::Yaml
} else { } else {
compile_error!("no config format feature enabled - build will fail!"); compile_error!("no config format feature enabled!");
Self::None
} }
} }
} }