diff --git a/Cargo.lock b/Cargo.lock index abc34c3..19cd3ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,17 +39,6 @@ dependencies = [ "syn", ] -[[package]] -name = "async-trait" -version = "0.1.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "autocfg" version = "1.2.0" @@ -758,7 +747,6 @@ dependencies = [ name = "reqwest-enum" version = "0.1.0" dependencies = [ - "async-trait", "futures", "reqwest", "serde", diff --git a/examples/ethereum-rpc/src/main.rs b/examples/ethereum-rpc/src/main.rs index aa3276a..4cfe74e 100644 --- a/examples/ethereum-rpc/src/main.rs +++ b/examples/ethereum-rpc/src/main.rs @@ -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> { diff --git a/reqwest-enum/Cargo.toml b/reqwest-enum/Cargo.toml index 2909cc6..5a4952f 100644 --- a/reqwest-enum/Cargo.toml +++ b/reqwest-enum/Cargo.toml @@ -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 } diff --git a/reqwest-enum/src/provider.rs b/reqwest-enum/src/provider.rs index 59daec6..ecad371 100644 --- a/reqwest-enum/src/provider.rs +++ b/reqwest-enum/src/provider.rs @@ -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 { +pub trait ProviderType: Send { /// request to target and return http response - async fn request(&self, target: T) -> Result; + fn request(&self, target: T) -> impl Future>; } -#[async_trait] pub trait JsonProviderType: ProviderType { /// request and deserialize response to json using serde - async fn request_json(&self, target: T) -> Result; + fn request_json( + &self, + target: T, + ) -> impl Future>; } #[cfg(feature = "jsonrpc")] -#[async_trait] + pub trait JsonRpcProviderType: ProviderType { /// batch isomorphic JSON-RPC requests - async fn batch( + fn batch( &self, targets: Vec, - ) -> Result>, JsonRpcError>; -} + ) -> impl Future>, JsonRpcError>>; -use core::future::Future; -use futures::future::join_all; -pub trait JsonRpcProviderType2: ProviderType { fn batch_chunk_by( &self, targets: Vec, @@ -48,7 +47,6 @@ pub struct Provider { client: Client, } -#[async_trait] impl ProviderType for Provider where T: Target + Send, @@ -60,7 +58,6 @@ where } } -#[async_trait] impl JsonProviderType for Provider where T: Target + Send, @@ -73,7 +70,6 @@ where } #[cfg(feature = "jsonrpc")] -#[async_trait] impl JsonRpcProviderType for Provider where T: JsonRpcTarget + Send, @@ -102,12 +98,7 @@ where let body = response.json::>>().await?; Ok(body) } -} -impl JsonRpcProviderType2 for Provider -where - T: JsonRpcTarget + Send, -{ async fn batch_chunk_by( &self, targets: Vec,