mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
deps(common_utils): put the async ext trait behind a feature (#835)
This commit is contained in:
@ -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"
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user