deps(common_utils): put the async ext trait behind a feature (#835)

This commit is contained in:
ItsMeShashank
2023-04-06 15:31:13 +05:30
committed by GitHub
parent 70dff14086
commit de29eb68b6
6 changed files with 23 additions and 12 deletions

View File

@ -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"

View File

@ -286,7 +286,8 @@ impl<T> StringExt<T> 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<A, B> {
/// Output type of the map function
type WrappedSelf<T>;
@ -307,7 +308,8 @@ pub trait AsyncExt<A, B> {
Fut: futures::Future<Output = Self::WrappedSelf<B>> + Send;
}
#[async_trait::async_trait]
#[cfg(feature = "async_ext")]
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
impl<A: Send, B, E: Send> AsyncExt<A, B> for Result<A, E> {
type WrappedSelf<T> = Result<T, E>;
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> {
}
}
#[async_trait::async_trait]
#[cfg(feature = "async_ext")]
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
impl<A: Send, B> AsyncExt<A, B> for Option<A> {
type WrappedSelf<T> = Option<T>;
async fn async_and_then<F, Fut>(self, func: F) -> Self::WrappedSelf<B>

View File

@ -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<T, Fut: futures::Future<Output = T>, F: FnOnce() -> Fut>(
block: F,
) -> (T, f64) {

View File

@ -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]

View File

@ -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" }