feat: with full support for rust services
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-11-26 22:19:34 +01:00
parent 80782e70f9
commit 7a1ad63b57
10 changed files with 593 additions and 25 deletions

View File

@@ -5,7 +5,7 @@ use std::{future::Future, pin::Pin};
#[async_trait]
pub trait DaggerMiddleware {
async fn handle(
&mut self,
&self,
container: dagger_sdk::Container,
) -> eyre::Result<dagger_sdk::Container> {
Ok(container)
@@ -14,14 +14,14 @@ pub trait DaggerMiddleware {
pub struct DaggerMiddlewareFn<F>
where
F: FnMut(Container) -> Pin<Box<dyn Future<Output = eyre::Result<Container>> + Send>>,
F: Fn(Container) -> Pin<Box<dyn Future<Output = eyre::Result<Container>> + Send>>,
{
pub func: F,
}
pub fn middleware<F>(func: F) -> Box<DaggerMiddlewareFn<F>>
where
F: FnMut(Container) -> Pin<Box<dyn Future<Output = eyre::Result<Container>> + Send>>,
F: Fn(Container) -> Pin<Box<dyn Future<Output = eyre::Result<Container>> + Send>>,
{
Box::new(DaggerMiddlewareFn { func })
}
@@ -29,11 +29,9 @@ where
#[async_trait]
impl<F> DaggerMiddleware for DaggerMiddlewareFn<F>
where
F: FnMut(Container) -> Pin<Box<dyn Future<Output = eyre::Result<Container>> + Send>>
+ Send
+ Sync,
F: Fn(Container) -> Pin<Box<dyn Future<Output = eyre::Result<Container>> + Send>> + Send + Sync,
{
async fn handle(&mut self, container: Container) -> eyre::Result<Container> {
async fn handle(&self, container: Container) -> eyre::Result<Container> {
// Call the closure stored in the struct
(self.func)(container).await
}