Skip to content

Commit de29eb6

Browse files
authored
deps(common_utils): put the async ext trait behind a feature (#835)
1 parent 70dff14 commit de29eb6

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common_utils/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,22 @@ signals = [
1212
"dep:signal-hook-tokio",
1313
"dep:signal-hook",
1414
"dep:tokio",
15-
"dep:router_env"
15+
"dep:router_env",
16+
"dep:futures"
17+
]
18+
async_ext = [
19+
"dep:futures",
20+
"dep:async-trait"
1621
]
1722
logs = [
1823
"dep:router_env"
1924
]
2025

2126
[dependencies]
22-
async-trait = "0.1.66"
27+
async-trait = { version = "0.1.66", optional = true }
2328
bytes = "1.4.0"
2429
error-stack = "0.3.1"
25-
futures = "0.3.27"
30+
futures = { version = "0.3.27", optional = true }
2631
hex = "0.4.3"
2732
nanoid = "0.4.0"
2833
once_cell = "1.17.1"

crates/common_utils/src/ext_traits.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ impl<T> StringExt<T> for String {
286286
///
287287
/// Extending functionalities of Wrapper types for idiomatic
288288
///
289-
#[async_trait::async_trait]
289+
#[cfg(feature = "async_ext")]
290+
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
290291
pub trait AsyncExt<A, B> {
291292
/// Output type of the map function
292293
type WrappedSelf<T>;
@@ -307,7 +308,8 @@ pub trait AsyncExt<A, B> {
307308
Fut: futures::Future<Output = Self::WrappedSelf<B>> + Send;
308309
}
309310

310-
#[async_trait::async_trait]
311+
#[cfg(feature = "async_ext")]
312+
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
311313
impl<A: Send, B, E: Send> AsyncExt<A, B> for Result<A, E> {
312314
type WrappedSelf<T> = Result<T, E>;
313315
async fn async_and_then<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
@@ -333,7 +335,8 @@ impl<A: Send, B, E: Send> AsyncExt<A, B> for Result<A, E> {
333335
}
334336
}
335337

336-
#[async_trait::async_trait]
338+
#[cfg(feature = "async_ext")]
339+
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
337340
impl<A: Send, B> AsyncExt<A, B> for Option<A> {
338341
type WrappedSelf<T> = Option<T>;
339342
async fn async_and_then<F, Fut>(self, func: F) -> Self::WrappedSelf<B>

crates/common_utils/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ pub mod validation;
1717
pub mod date_time {
1818
use std::num::NonZeroU8;
1919

20+
#[cfg(feature = "async_ext")]
21+
use time::Instant;
2022
use time::{
2123
format_description::well_known::iso8601::{Config, EncodedConfig, Iso8601, TimePrecision},
22-
Instant, OffsetDateTime, PrimitiveDateTime,
24+
OffsetDateTime, PrimitiveDateTime,
2325
};
2426
/// Struct to represent milliseconds in time sensitive data fields
2527
#[derive(Debug)]
@@ -42,6 +44,7 @@ pub mod date_time {
4244
}
4345

4446
/// Calculate execution time for a async block in milliseconds
47+
#[cfg(feature = "async_ext")]
4548
pub async fn time_it<T, Fut: futures::Future<Output = T>, F: FnOnce() -> Fut>(
4649
block: F,
4750
) -> (T, f64) {

crates/redis_interface/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ serde = { version = "1.0.155", features = ["derive"] }
1616
thiserror = "1.0.39"
1717

1818
# First party crates
19-
common_utils = { version = "0.1.0", path = "../common_utils" }
19+
common_utils = { version = "0.1.0", path = "../common_utils", features = ["async_ext"] }
2020
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }
2121

2222
[dev-dependencies]

crates/router/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ uuid = { version = "1.3.0", features = ["serde", "v4"] }
8080

8181
# First party crates
8282
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }
83-
common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals"] }
83+
common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals", "async_ext"] }
8484
external_services = { version = "0.1.0", path = "../external_services" }
8585
masking = { version = "0.1.0", path = "../masking" }
8686
redis_interface = { version = "0.1.0", path = "../redis_interface" }

0 commit comments

Comments
 (0)