diff --git a/Cargo.toml b/Cargo.toml index 3e54a456..93f39c7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -150,5 +150,9 @@ notify = "6.0" temp-env = "0.3" log = { version = "0.4", features = ["serde"] } +[[example]] +name = "async_source" +required-features = ["json", "async"] + [lints] workspace = true diff --git a/examples/custom_file_format/main.rs b/examples/custom_file_format/main.rs index e22901cf..2fd47b80 100644 --- a/examples/custom_file_format/main.rs +++ b/examples/custom_file_format/main.rs @@ -2,7 +2,7 @@ use config::{Config, File, FileStoredFormat, Format, Map, Value, ValueKind}; use std::io::{Error, ErrorKind}; /// The private and public key sources will be read into their associated variable: -#[derive(serde::Deserialize, Clone, Debug)] +#[derive(serde_derive::Deserialize, Clone, Debug)] pub struct Settings { pub private_key: Option, pub public_key: Option, diff --git a/src/builder.rs b/src/builder.rs index f511d255..465f3ae9 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -38,6 +38,8 @@ use crate::{config::Config, path::Expression, source::Source, value::Value}; /// # use config::*; /// # use std::error::Error; /// # fn main() -> Result<(), Box> { +/// # #[cfg(feature = "json")] +/// # { /// let mut builder = Config::builder() /// .set_default("default", "1")? /// .add_source(File::new("config/settings", FileFormat::Json)) @@ -52,6 +54,7 @@ use crate::{config::Config, path::Expression, source::Source, value::Value}; /// // something went wrong /// } /// } +/// # } /// # Ok(()) /// # } /// ``` @@ -64,11 +67,14 @@ use crate::{config::Config, path::Expression, source::Source, value::Value}; /// # use std::error::Error; /// # use config::*; /// # fn main() -> Result<(), Box> { +/// # #[cfg(feature = "json")] +/// # { /// let mut builder = Config::builder(); /// builder = builder.set_default("default", "1")?; /// builder = builder.add_source(File::new("config/settings", FileFormat::Json)); /// builder = builder.add_source(File::new("config/settings.prod", FileFormat::Json)); /// builder = builder.set_override("override", "1")?; +/// # } /// # Ok(()) /// # } /// ``` diff --git a/src/ser.rs b/src/ser.rs index 4d8f9778..bb5af9e3 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -679,6 +679,8 @@ impl ser::SerializeStructVariant for Unreachable { mod test { use super::*; use serde::{Deserialize, Serialize}; + #[cfg(not(feature = "json5"))] + use serde_derive::{Deserialize, Serialize}; #[test] fn test_struct() { @@ -699,6 +701,7 @@ mod test { } #[test] + #[cfg(feature = "json")] fn test_nest() { let val = serde_json::json! { { "top": { diff --git a/src/value.rs b/src/value.rs index 55f21d6c..c242c628 100644 --- a/src/value.rs +++ b/src/value.rs @@ -888,6 +888,7 @@ mod tests { use crate::FileFormat; #[test] + #[cfg(feature = "toml")] fn test_i64() { let c = Config::builder() .add_source(File::new("tests/types/i64.toml", FileFormat::Toml)) diff --git a/tests/async_builder.rs b/tests/async_builder.rs index 81c53bce..985b0ec7 100644 --- a/tests/async_builder.rs +++ b/tests/async_builder.rs @@ -1,3 +1,7 @@ +#![cfg(feature = "async")] +#![cfg(feature = "json")] +#![cfg(feature = "toml")] + use async_trait::async_trait; use config::{AsyncSource, Config, ConfigError, FileFormat, Format, Map, Value}; use std::{env, fs, path, str::FromStr}; diff --git a/tests/env.rs b/tests/env.rs index 30aaedb2..4befa5bb 100644 --- a/tests/env.rs +++ b/tests/env.rs @@ -522,6 +522,7 @@ fn test_parse_string_and_list_ignore_list_parse_key_case() { } #[test] +#[cfg(feature = "convert-case")] fn test_parse_nested_kebab() { use config::Case; diff --git a/tests/file.rs b/tests/file.rs index e14c8265..f9fb07f0 100644 --- a/tests/file.rs +++ b/tests/file.rs @@ -25,6 +25,7 @@ fn test_file_required_not_found() { } #[test] +#[cfg(feature = "toml")] fn test_file_auto() { let c = Config::builder() .add_source(File::with_name("tests/Settings-production")) @@ -49,6 +50,7 @@ fn test_file_auto_not_found() { } #[test] +#[cfg(feature = "json")] fn test_file_ext() { let c = Config::builder() .add_source(File::with_name("tests/Settings.json")) @@ -58,7 +60,9 @@ fn test_file_ext() { assert_eq!(c.get("debug").ok(), Some(true)); assert_eq!(c.get("production").ok(), Some(false)); } + #[test] +#[cfg(feature = "ini")] fn test_file_second_ext() { let c = Config::builder() .add_source(File::with_name("tests/Settings2.default")) diff --git a/tests/integer_range.rs b/tests/integer_range.rs index e80a2f2f..42292ea0 100644 --- a/tests/integer_range.rs +++ b/tests/integer_range.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "toml")] + use config::Config; #[test] diff --git a/tests/legacy/file.rs b/tests/legacy/file.rs index 11cedee1..a4ef41c7 100644 --- a/tests/legacy/file.rs +++ b/tests/legacy/file.rs @@ -23,6 +23,7 @@ fn test_file_required_not_found() { } #[test] +#[cfg(feature = "toml")] fn test_file_auto() { let mut c = Config::default(); c.merge(File::with_name("tests/Settings-production")) @@ -45,6 +46,7 @@ fn test_file_auto_not_found() { } #[test] +#[cfg(feature = "json")] fn test_file_ext() { let mut c = Config::default(); c.merge(File::with_name("tests/Settings.json")).unwrap(); diff --git a/tests/log.rs b/tests/log.rs index 4bb267f3..082c90f4 100644 --- a/tests/log.rs +++ b/tests/log.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "json")] + #[macro_use] extern crate serde_derive; @@ -33,6 +35,7 @@ fn test_case_sensitivity_log_level_from_str() { } #[test] +#[cfg(feature = "json")] fn test_case_sensitivity_json_from_str() { // to confirm serde_json works as expected let s = r#"{ "log": "error" }"#; diff --git a/tests/ron_enum.rs b/tests/ron_enum.rs index ee0264cf..fa0d96da 100644 --- a/tests/ron_enum.rs +++ b/tests/ron_enum.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "ron")] + use config::{Config, File, FileFormat}; use serde_derive::Deserialize; diff --git a/tests/unsigned_int.rs b/tests/unsigned_int.rs index 8656a012..0022314a 100644 --- a/tests/unsigned_int.rs +++ b/tests/unsigned_int.rs @@ -1,11 +1,11 @@ #![cfg(feature = "preserve_order")] -#[derive(serde::Deserialize, Eq, PartialEq, Debug)] +#[derive(serde_derive::Deserialize, Eq, PartialEq, Debug)] struct Container { inner: T, } -#[derive(serde::Deserialize, Eq, PartialEq, Debug)] +#[derive(serde_derive::Deserialize, Eq, PartialEq, Debug)] struct Unsigned { unsigned: u16, } diff --git a/tests/unsigned_int_hm.rs b/tests/unsigned_int_hm.rs index ab2a60cc..87d9a99a 100644 --- a/tests/unsigned_int_hm.rs +++ b/tests/unsigned_int_hm.rs @@ -1,11 +1,11 @@ #![cfg(not(feature = "preserve_order"))] -#[derive(serde::Deserialize, Eq, PartialEq, Debug)] +#[derive(serde_derive::Deserialize, Eq, PartialEq, Debug)] struct Container { inner: T, } -#[derive(serde::Deserialize, Eq, PartialEq, Debug)] +#[derive(serde_derive::Deserialize, Eq, PartialEq, Debug)] struct Unsigned { unsigned: u16, } diff --git a/tests/weird_keys.rs b/tests/weird_keys.rs index c997fe05..ef1749d1 100644 --- a/tests/weird_keys.rs +++ b/tests/weird_keys.rs @@ -4,6 +4,9 @@ // Please don't be offended! // +#![cfg(feature = "json")] +#![cfg(feature = "toml")] + use serde_derive::{Deserialize, Serialize}; use config::{File, FileFormat};