diff options
Diffstat (limited to 'libs/shared/src')
| -rw-r--r-- | libs/shared/src/nats.rs | 15 | ||||
| -rw-r--r-- | libs/shared/src/redis.rs | 16 |
2 files changed, 21 insertions, 10 deletions
diff --git a/libs/shared/src/nats.rs b/libs/shared/src/nats.rs index 7d4d3d1..1d835d3 100644 --- a/libs/shared/src/nats.rs +++ b/libs/shared/src/nats.rs @@ -1,4 +1,7 @@ -use std::{future::Future, pin::Pin}; +use std::{ + future::{Future, IntoFuture}, + pin::Pin, +}; use async_nats::Client; use serde::Deserialize; @@ -8,8 +11,12 @@ pub struct Configuration { pub host: String, } -impl From<Configuration> for Pin<Box<dyn Future<Output = anyhow::Result<Client>> + Send>> { - fn from(value: Configuration) -> Self { - Box::pin(async move { Ok(async_nats::connect(value.host).await?) }) +impl IntoFuture for Configuration { + type Output = anyhow::Result<Client>; + + type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>; + + fn into_future(self) -> Self::IntoFuture { + Box::pin(async move { Ok(async_nats::connect(self.host).await?) }) } } diff --git a/libs/shared/src/redis.rs b/libs/shared/src/redis.rs index 77aa97f..5cae869 100644 --- a/libs/shared/src/redis.rs +++ b/libs/shared/src/redis.rs @@ -1,18 +1,22 @@ use redis::{aio::MultiplexedConnection, Client}; use serde::Deserialize; -use std::{future::Future, pin::Pin}; +use std::{ + future::{Future, IntoFuture}, + pin::Pin, +}; #[derive(Clone, Debug, Deserialize)] pub struct Configuration { pub url: String, } -impl From<Configuration> - for Pin<Box<dyn Future<Output = anyhow::Result<MultiplexedConnection>> + Send>> -{ - fn from(value: Configuration) -> Self { +impl IntoFuture for Configuration { + type Output = anyhow::Result<MultiplexedConnection>; + type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>; + + fn into_future(self) -> Self::IntoFuture { Box::pin(async move { - let con = Client::open(value.url)?; + let con = Client::open(self.url)?; let (multiplex, ready) = con.create_multiplexed_tokio_connection().await?; tokio::spawn(ready); |
