Skip to content

Commit

Permalink
remove async-trait
Browse files Browse the repository at this point in the history
  • Loading branch information
hewigovens committed Apr 4, 2024
1 parent 52c5f84 commit 94f57c8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 36 deletions.
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/ethereum-rpc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate reqwest_enum;
use ethereum_rpc::EthereumRPC;
use reqwest_enum::jsonrpc::JsonRpcResult;
use reqwest_enum::provider::{JsonRpcProviderType, JsonRpcProviderType2, Provider};
use reqwest_enum::provider::{JsonRpcProviderType, Provider};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
1 change: 0 additions & 1 deletion reqwest-enum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ jsonrpc = ["dep:futures"]
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
async-trait = { workspace = true }
futures = { workspace = true, optional = true }
35 changes: 13 additions & 22 deletions reqwest-enum/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
#[cfg(feature = "jsonrpc")]
use crate::jsonrpc::{JsonRpcError, JsonRpcRequest, JsonRpcResult, JsonRpcTarget};
#[cfg(feature = "jsonrpc")]
use futures::future::join_all;

use crate::{
http::{HTTPBody, HTTPResponse},
target::Target,
};

use async_trait::async_trait;
use core::future::Future;
use reqwest::{Client, Error};
use serde::de::DeserializeOwned;

#[async_trait]
pub trait ProviderType<T: Target> {
pub trait ProviderType<T: Target>: Send {
/// request to target and return http response
async fn request(&self, target: T) -> Result<HTTPResponse, Error>;
fn request(&self, target: T) -> impl Future<Output = Result<HTTPResponse, Error>>;
}

#[async_trait]
pub trait JsonProviderType<T: Target>: ProviderType<T> {
/// request and deserialize response to json using serde
async fn request_json<U: DeserializeOwned>(&self, target: T) -> Result<U, Error>;
fn request_json<U: DeserializeOwned>(
&self,
target: T,
) -> impl Future<Output = Result<U, Error>>;
}

#[cfg(feature = "jsonrpc")]
#[async_trait]

pub trait JsonRpcProviderType<T: Target>: ProviderType<T> {
/// batch isomorphic JSON-RPC requests
async fn batch<U: DeserializeOwned>(
fn batch<U: DeserializeOwned>(
&self,
targets: Vec<T>,
) -> Result<Vec<JsonRpcResult<U>>, JsonRpcError>;
}
) -> impl Future<Output = Result<Vec<JsonRpcResult<U>>, JsonRpcError>>;

use core::future::Future;
use futures::future::join_all;
pub trait JsonRpcProviderType2<T: Target>: ProviderType<T> {
fn batch_chunk_by<U: DeserializeOwned>(
&self,
targets: Vec<T>,
Expand All @@ -48,7 +47,6 @@ pub struct Provider<T: Target> {
client: Client,
}

#[async_trait]
impl<T> ProviderType<T> for Provider<T>
where
T: Target + Send,
Expand All @@ -60,7 +58,6 @@ where
}
}

#[async_trait]
impl<T> JsonProviderType<T> for Provider<T>
where
T: Target + Send,
Expand All @@ -73,7 +70,6 @@ where
}

#[cfg(feature = "jsonrpc")]
#[async_trait]
impl<T> JsonRpcProviderType<T> for Provider<T>
where
T: JsonRpcTarget + Send,
Expand Down Expand Up @@ -102,12 +98,7 @@ where
let body = response.json::<Vec<JsonRpcResult<U>>>().await?;
Ok(body)
}
}

impl<T> JsonRpcProviderType2<T> for Provider<T>
where
T: JsonRpcTarget + Send,
{
async fn batch_chunk_by<U: DeserializeOwned>(
&self,
targets: Vec<T>,
Expand Down

0 comments on commit 94f57c8

Please sign in to comment.