From de29eb68b64ce5318aafc811dfda4ba0ce40df12 Mon Sep 17 00:00:00 2001 From: ItsMeShashank Date: Thu, 6 Apr 2023 15:31:13 +0530 Subject: [PATCH] deps(common_utils): put the async ext trait behind a feature (#835) --- Cargo.lock | 6 +++--- crates/common_utils/Cargo.toml | 11 ++++++++--- crates/common_utils/src/ext_traits.rs | 9 ++++++--- crates/common_utils/src/lib.rs | 5 ++++- crates/redis_interface/Cargo.toml | 2 +- crates/router/Cargo.toml | 2 +- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e585ced7f..dc8668a5e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5042,13 +5042,13 @@ dependencies = [ [[package]] name = "wiremock" -version = "0.5.17" +version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12316b50eb725e22b2f6b9c4cbede5b7b89984274d113a7440c86e5c3fc6f99b" +checksum = "bd7b0b5b253ebc0240d6aac6dd671c495c467420577bf634d3064ae7e6fa2b4c" dependencies = [ "assert-json-diff", "async-trait", - "base64 0.13.1", + "base64 0.21.0", "deadpool", "futures", "futures-timer", diff --git a/crates/common_utils/Cargo.toml b/crates/common_utils/Cargo.toml index 5c60265d5a..d0a367e842 100644 --- a/crates/common_utils/Cargo.toml +++ b/crates/common_utils/Cargo.toml @@ -12,17 +12,22 @@ signals = [ "dep:signal-hook-tokio", "dep:signal-hook", "dep:tokio", - "dep:router_env" + "dep:router_env", + "dep:futures" +] +async_ext = [ + "dep:futures", + "dep:async-trait" ] logs = [ "dep:router_env" ] [dependencies] -async-trait = "0.1.66" +async-trait = { version = "0.1.66", optional = true } bytes = "1.4.0" error-stack = "0.3.1" -futures = "0.3.27" +futures = { version = "0.3.27", optional = true } hex = "0.4.3" nanoid = "0.4.0" once_cell = "1.17.1" diff --git a/crates/common_utils/src/ext_traits.rs b/crates/common_utils/src/ext_traits.rs index c68b57e0f8..29a24449d9 100644 --- a/crates/common_utils/src/ext_traits.rs +++ b/crates/common_utils/src/ext_traits.rs @@ -286,7 +286,8 @@ impl StringExt for String { /// /// Extending functionalities of Wrapper types for idiomatic /// -#[async_trait::async_trait] +#[cfg(feature = "async_ext")] +#[cfg_attr(feature = "async_ext", async_trait::async_trait)] pub trait AsyncExt { /// Output type of the map function type WrappedSelf; @@ -307,7 +308,8 @@ pub trait AsyncExt { Fut: futures::Future> + Send; } -#[async_trait::async_trait] +#[cfg(feature = "async_ext")] +#[cfg_attr(feature = "async_ext", async_trait::async_trait)] impl AsyncExt for Result { type WrappedSelf = Result; async fn async_and_then(self, func: F) -> Self::WrappedSelf @@ -333,7 +335,8 @@ impl AsyncExt for Result { } } -#[async_trait::async_trait] +#[cfg(feature = "async_ext")] +#[cfg_attr(feature = "async_ext", async_trait::async_trait)] impl AsyncExt for Option { type WrappedSelf = Option; async fn async_and_then(self, func: F) -> Self::WrappedSelf diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs index 07406d50bb..b181cdcf4d 100644 --- a/crates/common_utils/src/lib.rs +++ b/crates/common_utils/src/lib.rs @@ -17,9 +17,11 @@ pub mod validation; pub mod date_time { use std::num::NonZeroU8; + #[cfg(feature = "async_ext")] + use time::Instant; use time::{ format_description::well_known::iso8601::{Config, EncodedConfig, Iso8601, TimePrecision}, - Instant, OffsetDateTime, PrimitiveDateTime, + OffsetDateTime, PrimitiveDateTime, }; /// Struct to represent milliseconds in time sensitive data fields #[derive(Debug)] @@ -42,6 +44,7 @@ pub mod date_time { } /// Calculate execution time for a async block in milliseconds + #[cfg(feature = "async_ext")] pub async fn time_it, F: FnOnce() -> Fut>( block: F, ) -> (T, f64) { diff --git a/crates/redis_interface/Cargo.toml b/crates/redis_interface/Cargo.toml index e71422c10e..de248ff6b7 100644 --- a/crates/redis_interface/Cargo.toml +++ b/crates/redis_interface/Cargo.toml @@ -16,7 +16,7 @@ serde = { version = "1.0.155", features = ["derive"] } thiserror = "1.0.39" # First party crates -common_utils = { version = "0.1.0", path = "../common_utils" } +common_utils = { version = "0.1.0", path = "../common_utils", features = ["async_ext"] } router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] } [dev-dependencies] diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml index 770d2998a6..6a2263e539 100644 --- a/crates/router/Cargo.toml +++ b/crates/router/Cargo.toml @@ -80,7 +80,7 @@ uuid = { version = "1.3.0", features = ["serde", "v4"] } # First party crates api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] } -common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals"] } +common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals", "async_ext"] } external_services = { version = "0.1.0", path = "../external_services" } masking = { version = "0.1.0", path = "../masking" } redis_interface = { version = "0.1.0", path = "../redis_interface" }