Skip to content

Commit 5a9f666

Browse files
committed
Gate async-traits behind a feature
1 parent 74bdf5e commit 5a9f666

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@ edition = "2018"
1515
maintenance = { status = "actively-developed" }
1616

1717
[features]
18-
default = ["toml", "json", "yaml", "ini", "ron", "json5", "convert-case"]
18+
default = ["toml", "json", "yaml", "ini", "ron", "json5", "convert-case", "async"]
1919
json = ["serde_json"]
2020
yaml = ["yaml-rust"]
2121
ini = ["rust-ini"]
2222
json5 = ["json5_rs"]
2323
convert-case = ["convert_case"]
2424
preserve_order = ["indexmap", "toml/preserve_order", "serde_json/preserve_order", "ron/indexmap"]
25+
async = ["async-trait"]
2526

2627
[dependencies]
27-
async-trait = "0.1.50"
2828
lazy_static = "1.0"
2929
serde = "1.0.8"
3030
nom = "7"
3131

32+
async-trait = { version = "0.1.50", optional = true }
3233
toml = { version = "0.5", optional = true }
3334
serde_json = { version = "1.0.2", optional = true }
3435
yaml-rust = { version = "0.4", optional = true }

src/builder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::iter::IntoIterator;
21
use std::str::FromStr;
32

43
use crate::error::Result;
54
use crate::map::Map;
5+
#[cfg(feature = "async")]
66
use crate::source::AsyncSource;
77
use crate::{config::Config, path::Expression, source::Source, value::Value};
88

@@ -132,6 +132,7 @@ pub struct AsyncState {
132132
#[derive(Debug, Clone)]
133133
enum SourceType {
134134
Sync(Box<dyn Source + Send + Sync>),
135+
#[cfg(feature = "async")]
135136
Async(Box<dyn AsyncSource + Send + Sync>),
136137
}
137138

@@ -213,6 +214,7 @@ impl ConfigBuilder<DefaultState> {
213214
/// Registers new [`AsyncSource`] in this builder and forces transition to [`AsyncState`].
214215
///
215216
/// Calling this method does not invoke any I/O. [`AsyncSource`] is only saved in internal register for later use.
217+
#[cfg(feature = "async")]
216218
pub fn add_async_source<T>(self, source: T) -> ConfigBuilder<AsyncState>
217219
where
218220
T: AsyncSource + Send + Sync + 'static,
@@ -302,6 +304,7 @@ impl ConfigBuilder<AsyncState> {
302304
/// Registers new [`AsyncSource`] in this builder.
303305
///
304306
/// Calling this method does not invoke any I/O. [`AsyncSource`] is only saved in internal register for later use.
307+
#[cfg(feature = "async")]
305308
pub fn add_async_source<T>(mut self, source: T) -> Self
306309
where
307310
T: AsyncSource + Send + Sync + 'static,
@@ -354,6 +357,7 @@ impl ConfigBuilder<AsyncState> {
354357
for source in sources.iter() {
355358
match source {
356359
SourceType::Sync(source) => source.collect_to(&mut cache)?,
360+
#[cfg(feature = "async")]
357361
SourceType::Async(source) => source.collect_to(&mut cache).await?,
358362
}
359363
}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ pub use crate::error::ConfigError;
4040
pub use crate::file::{File, FileFormat, FileSourceFile, FileSourceString, FileStoredFormat};
4141
pub use crate::format::Format;
4242
pub use crate::map::Map;
43-
pub use crate::source::{AsyncSource, Source};
43+
#[cfg(feature = "async")]
44+
pub use crate::source::AsyncSource;
45+
pub use crate::source::Source;
4446
pub use crate::value::{Value, ValueKind};
4547

4648
// Re-export

src/source.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt::Debug;
22
use std::str::FromStr;
33

4+
#[cfg(feature = "async")]
45
use async_trait::async_trait;
56

67
use crate::error::Result;
@@ -50,6 +51,7 @@ fn set_value(cache: &mut Value, key: &str, value: &Value) {
5051
/// It is advised to use `async_trait` crate while implementing this trait.
5152
///
5253
/// See examples for sample implementation.
54+
#[cfg(feature = "async")]
5355
#[async_trait]
5456
pub trait AsyncSource: Debug + Sync {
5557
// 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 {
6971
}
7072
}
7173

74+
#[cfg(feature = "async")]
7275
impl Clone for Box<dyn AsyncSource + Send + Sync> {
7376
fn clone(&self) -> Self {
7477
self.to_owned()

0 commit comments

Comments
 (0)