diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2022-12-06 17:09:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-06 17:09:32 +0100 |
commit | 47e1b7cce6ca6e2419bc6300340050479a292b55 (patch) | |
tree | e38f2b24329e8d5e6ed3227acba24d24ba67c0b4 | |
parent | 74bdf5e766450c7c93f9121951d72b23f2b6b14d (diff) | |
parent | 5a9f666a55ebb769e45e2b8a8477909a57855170 (diff) |
Merge pull request #402 from nstinus/master
Gate async-traits behind a feature
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | src/builder.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/source.rs | 3 |
4 files changed, 14 insertions, 4 deletions
@@ -15,20 +15,21 @@ edition = "2018" maintenance = { status = "actively-developed" } [features] -default = ["toml", "json", "yaml", "ini", "ron", "json5", "convert-case"] +default = ["toml", "json", "yaml", "ini", "ron", "json5", "convert-case", "async"] json = ["serde_json"] yaml = ["yaml-rust"] ini = ["rust-ini"] json5 = ["json5_rs"] convert-case = ["convert_case"] preserve_order = ["indexmap", "toml/preserve_order", "serde_json/preserve_order", "ron/indexmap"] +async = ["async-trait"] [dependencies] -async-trait = "0.1.50" lazy_static = "1.0" serde = "1.0.8" nom = "7" +async-trait = { version = "0.1.50", optional = true } toml = { version = "0.5", optional = true } serde_json = { version = "1.0.2", optional = true } yaml-rust = { version = "0.4", optional = true } diff --git a/src/builder.rs b/src/builder.rs index 9eb367c..db6ee2f 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,8 +1,8 @@ -use std::iter::IntoIterator; use std::str::FromStr; use crate::error::Result; use crate::map::Map; +#[cfg(feature = "async")] use crate::source::AsyncSource; use crate::{config::Config, path::Expression, source::Source, value::Value}; @@ -132,6 +132,7 @@ pub struct AsyncState { #[derive(Debug, Clone)] enum SourceType { Sync(Box<dyn Source + Send + Sync>), + #[cfg(feature = "async")] Async(Box<dyn AsyncSource + Send + Sync>), } @@ -213,6 +214,7 @@ impl ConfigBuilder<DefaultState> { /// Registers new [`AsyncSource`] in this builder and forces transition to [`AsyncState`]. /// /// Calling this method does not invoke any I/O. [`AsyncSource`] is only saved in internal register for later use. + #[cfg(feature = "async")] pub fn add_async_source<T>(self, source: T) -> ConfigBuilder<AsyncState> where T: AsyncSource + Send + Sync + 'static, @@ -302,6 +304,7 @@ impl ConfigBuilder<AsyncState> { /// Registers new [`AsyncSource`] in this builder. /// /// Calling this method does not invoke any I/O. [`AsyncSource`] is only saved in internal register for later use. + #[cfg(feature = "async")] pub fn add_async_source<T>(mut self, source: T) -> Self where T: AsyncSource + Send + Sync + 'static, @@ -354,6 +357,7 @@ impl ConfigBuilder<AsyncState> { for source in sources.iter() { match source { SourceType::Sync(source) => source.collect_to(&mut cache)?, + #[cfg(feature = "async")] SourceType::Async(source) => source.collect_to(&mut cache).await?, } } @@ -40,7 +40,9 @@ pub use crate::error::ConfigError; pub use crate::file::{File, FileFormat, FileSourceFile, FileSourceString, FileStoredFormat}; pub use crate::format::Format; pub use crate::map::Map; -pub use crate::source::{AsyncSource, Source}; +#[cfg(feature = "async")] +pub use crate::source::AsyncSource; +pub use crate::source::Source; pub use crate::value::{Value, ValueKind}; // Re-export diff --git a/src/source.rs b/src/source.rs index 94f1c35..16e1938 100644 --- a/src/source.rs +++ b/src/source.rs @@ -1,6 +1,7 @@ use std::fmt::Debug; use std::str::FromStr; +#[cfg(feature = "async")] use async_trait::async_trait; use crate::error::Result; @@ -50,6 +51,7 @@ fn set_value(cache: &mut Value, key: &str, value: &Value) { /// It is advised to use `async_trait` crate while implementing this trait. /// /// See examples for sample implementation. +#[cfg(feature = "async")] #[async_trait] pub trait AsyncSource: Debug + Sync { // Sync is supertrait due to https://docs.rs/async-trait/0.1.50/async_trait/index.html#dyn-traits @@ -69,6 +71,7 @@ pub trait AsyncSource: Debug + Sync { } } +#[cfg(feature = "async")] impl Clone for Box<dyn AsyncSource + Send + Sync> { fn clone(&self) -> Self { self.to_owned() |