strut_rabbitmq/transport/inbound/envelope/
stack.rs1use crate::Envelope;
2use async_trait::async_trait;
3use futures::future::join_all;
4use nonempty::NonEmpty;
5
6#[async_trait]
9pub trait EnvelopeStack {
10 async fn complete_all(self);
13
14 async fn backwash_all(self);
17
18 async fn abandon_all(self);
21}
22
23#[async_trait]
25impl<T> EnvelopeStack for Vec<Envelope<T>>
26where
27 T: Send,
28{
29 async fn complete_all(self) {
30 join_all(self.into_iter().map(|envelope| envelope.complete())).await;
31 }
32
33 async fn backwash_all(self) {
34 join_all(self.into_iter().map(|envelope| envelope.backwash())).await;
35 }
36
37 async fn abandon_all(self) {
38 join_all(self.into_iter().map(|envelope| envelope.abandon())).await;
39 }
40}
41
42#[async_trait]
44impl<T> EnvelopeStack for NonEmpty<Envelope<T>>
45where
46 T: Send,
47{
48 async fn complete_all(self) {
49 join_all(self.into_iter().map(|envelope| envelope.complete())).await;
50 }
51
52 async fn backwash_all(self) {
53 join_all(self.into_iter().map(|envelope| envelope.backwash())).await;
54 }
55
56 async fn abandon_all(self) {
57 join_all(self.into_iter().map(|envelope| envelope.abandon())).await;
58 }
59}