Skip to content

Commit 10c2e68

Browse files
linkmauveFlashSystems
authored andcommitted
Remove async-trait dependency
Since Rust 1.75.0, async fn can be used in traits. This removes the dependency on the async-trait dependency, and fixes a slight error this proc-macro was hiding, replacing it with a normal function returning an impl Future.
1 parent f6f16e9 commit 10c2e68

3 files changed

Lines changed: 3 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ byteorder = "1"
2020
[dev-dependencies]
2121
tokio = { version = "1", features = ["test-util", "net", "rt-multi-thread"] }
2222
tokio-test = "0.4"
23-
async-trait = "0.1"

examples/apiserver.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{sync::Arc, collections::HashMap, io::Read};
22

3-
use async_trait::async_trait;
43
use tokio::{net::{TcpListener, tcp::OwnedWriteHalf}, sync::RwLock};
54
use tokio_fastcgi::{Requests, RequestResult, Request};
65

@@ -80,7 +79,6 @@ impl HttpResponse {
8079

8180
/// Request handler trait. All request handlers have to implement this async trait.
8281
/// The default implementation for every method returns the 405 (Method Not Allowed) error code.
83-
#[async_trait]
8482
trait RequestHandler {
8583
async fn get(_store: Arc<RwLock<Store>>, _request: &Request<OwnedWriteHalf>, _selector: Option<u32>) -> Result<String, HttpResponse> {
8684
Err(HttpResponse::e405())
@@ -115,7 +113,6 @@ impl Store {
115113
/// Handles the REST API for quotes.
116114
struct Quotes {}
117115

118-
#[async_trait]
119116
impl RequestHandler for Quotes {
120117
/// Get returns the quote stored for the given selector u32 or 404 (Not Found).
121118
async fn get(store: Arc<RwLock<Store>>, _request: &Request<OwnedWriteHalf>, selector: Option<u32>) -> Result<String, HttpResponse> {
@@ -189,7 +186,6 @@ impl RequestHandler for Quotes {
189186
/// Handle ping requests on /api/ping
190187
struct Ping {}
191188

192-
#[async_trait]
193189
impl RequestHandler for Ping {
194190
async fn get(_store: Arc<RwLock<Store>>, _request: &Request<OwnedWriteHalf>, _selector: Option<u32>) -> Result<String, HttpResponse> {
195191
Ok("pong".to_string())

tests/commons.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use std::sync::Arc;
1313
use std::time::Duration;
1414
use std::io::Read;
1515
use std::convert::From;
16+
use std::future::Future;
1617
use tokio::io::AsyncWrite;
17-
use async_trait::async_trait;
1818

1919
pub enum RecordType {
2020
BeginRequest = 1,
@@ -53,16 +53,14 @@ pub fn create_record(request_type: RecordType, request_id: u8, padding: u8, data
5353
record
5454
}
5555

56-
#[async_trait]
5756
pub trait TestCase {
5857
fn get_input() -> Mock;
5958
fn get_output() -> Mock;
60-
async fn processor<W: AsyncWrite + Unpin + Send>(request: Arc<Request<W>>) -> RequestResult;
59+
fn processor<W: AsyncWrite + Unpin + Send>(request: Arc<Request<W>>) -> impl Future<Output = RequestResult> + Send;
6160
}
6261

6362
pub struct TestParamsInOut {}
6463

65-
#[async_trait]
6664
impl TestCase for TestParamsInOut {
6765
fn get_input() -> Mock {
6866
Builder::new()
@@ -142,7 +140,6 @@ impl TestCase for TestParamsInOut {
142140

143141
pub struct TestRoleAuthorizer {}
144142

145-
#[async_trait]
146143
impl TestCase for TestRoleAuthorizer {
147144
fn get_input() -> Mock {
148145
Builder::new()
@@ -175,7 +172,6 @@ impl TestCase for TestRoleAuthorizer {
175172

176173
pub struct TestRoleFilter {}
177174

178-
#[async_trait]
179175
impl TestCase for TestRoleFilter {
180176
fn get_input() -> Mock {
181177
Builder::new()
@@ -219,7 +215,6 @@ impl TestCase for TestRoleFilter {
219215

220216
pub struct TestAbortRequest {}
221217

222-
#[async_trait]
223218
impl TestCase for TestAbortRequest {
224219
fn get_input() -> Mock {
225220
Builder::new()
@@ -243,7 +238,6 @@ impl TestCase for TestAbortRequest {
243238

244239
pub struct TestAbortContinue {}
245240

246-
#[async_trait]
247241
impl TestCase for TestAbortContinue {
248242
fn get_input() -> Mock {
249243
Builder::new()
@@ -279,7 +273,6 @@ impl TestCase for TestAbortContinue {
279273

280274
pub struct TestUnknownRoleReturn {}
281275

282-
#[async_trait]
283276
impl TestCase for TestUnknownRoleReturn {
284277
fn get_input() -> Mock {
285278
Builder::new()
@@ -306,7 +299,6 @@ impl TestCase for TestUnknownRoleReturn {
306299

307300
pub struct TestUnknownRoleRequest {}
308301

309-
#[async_trait]
310302
impl TestCase for TestUnknownRoleRequest {
311303
fn get_input() -> Mock {
312304
Builder::new()
@@ -331,7 +323,6 @@ impl TestCase for TestUnknownRoleRequest {
331323

332324
pub struct TestUnknownRequestType {}
333325

334-
#[async_trait]
335326
impl TestCase for TestUnknownRequestType {
336327
fn get_input() -> Mock {
337328
Builder::new()
@@ -355,7 +346,6 @@ impl TestCase for TestUnknownRequestType {
355346

356347
pub struct TestGetValues {}
357348

358-
#[async_trait]
359349
impl TestCase for TestGetValues {
360350
fn get_input() -> Mock {
361351
Builder::new()
@@ -380,7 +370,6 @@ impl TestCase for TestGetValues {
380370
pub struct TestKeepConnection {
381371
}
382372

383-
#[async_trait]
384373
impl TestCase for TestKeepConnection {
385374
fn get_input() -> Mock {
386375
Builder::new()
@@ -423,4 +412,4 @@ impl TestCase for TestKeepConnection {
423412
request.get_stderr().write(&[b'X', idx.as_bytes()[0] - b'1' + b'A']).await.unwrap();
424413
RequestResult::Complete(0x11223344 * idx.parse().unwrap_or(0))
425414
}
426-
}
415+
}

0 commit comments

Comments
 (0)