summaryrefslogtreecommitdiff
path: root/libs/shared/src
diff options
context:
space:
mode:
authorMatthieuCoder <matthieu@matthieu-dev.xyz>2023-01-18 16:03:11 +0400
committerMatthieuCoder <matthieu@matthieu-dev.xyz>2023-01-18 16:03:11 +0400
commit7f4406d0946d409a842b4b364541380e50d92010 (patch)
tree1fecd2717a09bc3256822c1f0a0617f1d4abe272 /libs/shared/src
parentcbaa1665485b0d5fc52a54ff15a5e4b491e3c671 (diff)
base
Diffstat (limited to 'libs/shared/src')
-rw-r--r--libs/shared/src/nats.rs15
-rw-r--r--libs/shared/src/redis.rs16
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);