context_async/
with.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::future::Future;
use crate::Context;

#[async_trait::async_trait]
pub trait With<Output> {
    async fn with<Ctx>(self, ctx: Ctx) -> crate::Result<Output>
    where
        Ctx: Context + Send;
}

#[async_trait::async_trait]
impl<'a, Output, Fut> With<Output> for Fut
where
    Fut: Future<Output = Output> + Send + 'a
{
    async fn with<Ctx>(self, ctx: Ctx) -> crate::Result<Output>
    where
        Ctx: Context + Send,
    {
        ctx.handle(self).await
    }
}