Skip to content

Commit

Permalink
refactor: move is_local to transport
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Aug 2, 2023
1 parent b8dbb9a commit 763a5c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
5 changes: 2 additions & 3 deletions crates/transports/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,12 @@ where

pub struct ClientBuilder<L> {
builder: ServiceBuilder<L>,
is_local: bool,
}

impl<L> ClientBuilder<L> {
pub fn layer<M>(self, layer: M) -> ClientBuilder<tower::layer::util::Stack<M, L>> {
ClientBuilder {
builder: self.builder.layer(layer),
is_local: self.is_local,
}
}

Expand All @@ -93,7 +91,8 @@ impl<L> ClientBuilder<L> {
L::Service: Transport + Clone,
<L::Service as tower::Service<Box<RawValue>>>::Future: Send,
{
RpcClient::new(self.builder.service(transport), self.is_local)
let is_local = transport.is_local();
RpcClient::new(self.builder.service(transport), is_local)
}
}

Expand Down
8 changes: 7 additions & 1 deletion crates/transports/src/transports/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_json::value::RawValue;
use std::{future::Future, pin::Pin, str::FromStr, sync::atomic::AtomicU64, task};
use tower::Service;

use crate::{client::RpcClient, error::TransportError};
use crate::{client::RpcClient, error::TransportError, Transport};

impl<T> RpcClient<Http<T>>
where
Expand Down Expand Up @@ -88,3 +88,9 @@ impl Service<Box<RawValue>> for Http<reqwest::Client> {
})
}
}

impl Transport for Http<reqwest::Client> {
fn is_local(&self) -> bool {
self.is_local()
}
}
15 changes: 1 addition & 14 deletions crates/transports/src/transports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,7 @@ pub trait Transport:
+ Send
+ 'static
{
}

impl<T> Transport for T
where
T: Service<
Box<RawValue>,
Response = Box<RawValue>,
Error = TransportError,
Future = Pin<Box<dyn Future<Output = Result<Box<RawValue>, TransportError>> + Send>>,
> + Clone
+ Send
+ 'static,
T::Future: Send + 'static,
{
fn is_local(&self) -> bool;
}

#[must_use = "futures do nothing unless you `.await` or poll them"]
Expand Down

0 comments on commit 763a5c6

Please sign in to comment.