diff --git a/rscx/Cargo.toml b/rscx/Cargo.toml index aa9a0cc..270342b 100644 --- a/rscx/Cargo.toml +++ b/rscx/Cargo.toml @@ -11,7 +11,9 @@ readme = "../README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +async-trait = "0.1.73" axum = { version = "0.6.20", features = ["macros"], optional = true } +futures = "0.3.28" html-escape = "0.2.13" rscx-macros = { workspace = true } tokio = { version = "1.32.0", features = ["full"] } diff --git a/rscx/src/lib.rs b/rscx/src/lib.rs index 8692416..1d86644 100644 --- a/rscx/src/lib.rs +++ b/rscx/src/lib.rs @@ -3,12 +3,17 @@ pub mod axum; pub mod context; pub extern crate rscx_macros; +use std::future::Future; + pub use rscx_macros::*; pub extern crate typed_builder; pub extern crate html_escape; +use async_trait::async_trait; +use futures::future::join_all; + pub trait CollectFragment where I: Iterator, @@ -26,3 +31,25 @@ where self.collect::>().join("") } } + +#[async_trait] +pub trait CollectFragmentAsync +where + I: Iterator, + Vec: FromIterator<::Item>, + Fut: Future, +{ + async fn collect_fragment_async(self) -> String; +} + +#[async_trait] +impl CollectFragmentAsync for I +where + I: Iterator + Send, + Vec: FromIterator<::Item>, + Fut: Future + Send, +{ + async fn collect_fragment_async(self) -> String { + join_all(self.collect::>()).await.join("") + } +}