Skip to content

Commit

Permalink
add collect_fragment_async() helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed Sep 9, 2023
1 parent 31f3c80 commit b00fb17
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rscx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
27 changes: 27 additions & 0 deletions rscx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I>
where
I: Iterator,
Expand All @@ -26,3 +31,25 @@ where
self.collect::<Vec<String>>().join("")
}
}

#[async_trait]
pub trait CollectFragmentAsync<I, Fut>
where
I: Iterator,
Vec<Fut>: FromIterator<<I as Iterator>::Item>,
Fut: Future<Output = String>,
{
async fn collect_fragment_async(self) -> String;
}

#[async_trait]
impl<I, Fut> CollectFragmentAsync<I, Fut> for I
where
I: Iterator + Send,
Vec<Fut>: FromIterator<<I as Iterator>::Item>,
Fut: Future<Output = String> + Send,
{
async fn collect_fragment_async(self) -> String {
join_all(self.collect::<Vec<_>>()).await.join("")
}
}

0 comments on commit b00fb17

Please sign in to comment.