From dbe377ab06b2078d136346ef772775ce1e8dcf5f Mon Sep 17 00:00:00 2001 From: Yiannis Marangos Date: Fri, 26 Apr 2024 00:04:20 +0300 Subject: [PATCH] feat!: Use RTITIT instead of async-trait --- Cargo.toml | 4 ++-- examples/tftpd-targz.rs | 1 - src/lib.rs | 3 --- src/server/handler.rs | 11 ++++++----- src/server/handlers/dir.rs | 1 - src/tests/handlers.rs | 1 - 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7506397..f229308 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,8 @@ name = "async-tftp" version = "0.3.6" authors = ["oblique "] -edition = "2018" +edition = "2021" +rust-version = "1.75" license = "MIT" readme = "README.md" @@ -20,7 +21,6 @@ thiserror = "1.0.48" async-executor = "1.5.1" async-io = "1.13.0" async-lock = "2.8.0" -async-trait = "0.1.73" blocking = "1.3.1" futures-lite = "1.13.0" diff --git a/examples/tftpd-targz.rs b/examples/tftpd-targz.rs index 703adbc..32c72f8 100644 --- a/examples/tftpd-targz.rs +++ b/examples/tftpd-targz.rs @@ -29,7 +29,6 @@ fn strip_path_prefixes(path: &Path) -> &Path { path.strip_prefix("/").or_else(|_| path.strip_prefix("./")).unwrap_or(path) } -#[async_tftp::async_trait] impl Handler for TftpdTarGzHandler { type Reader = Entry>>>; type Writer = Sink; diff --git a/src/lib.rs b/src/lib.rs index bda851a..eb1e1f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,6 +67,3 @@ mod tests; mod utils; pub use crate::error::*; - -/// Re-export of `async_trait:async_trait`. -pub use async_trait::async_trait; diff --git a/src/server/handler.rs b/src/server/handler.rs index 21097c4..faa4df9 100644 --- a/src/server/handler.rs +++ b/src/server/handler.rs @@ -1,27 +1,28 @@ use futures_lite::{AsyncRead, AsyncWrite}; +use std::future::Future; use std::net::SocketAddr; use std::path::Path; use crate::packet; /// Trait for implementing advance handlers. -#[crate::async_trait] pub trait Handler: Send { type Reader: AsyncRead + Unpin + Send + 'static; type Writer: AsyncWrite + Unpin + Send + 'static; /// Open `Reader` to serve a read request. - async fn read_req_open( + fn read_req_open( &mut self, client: &SocketAddr, path: &Path, - ) -> Result<(Self::Reader, Option), packet::Error>; + ) -> impl Future), packet::Error>> + + Send; /// Open `Writer` to serve a write request. - async fn write_req_open( + fn write_req_open( &mut self, client: &SocketAddr, path: &Path, size: Option, - ) -> Result; + ) -> impl Future> + Send; } diff --git a/src/server/handlers/dir.rs b/src/server/handlers/dir.rs index ef907fb..d3bf895 100644 --- a/src/server/handlers/dir.rs +++ b/src/server/handlers/dir.rs @@ -59,7 +59,6 @@ impl DirHandler { } } -#[crate::async_trait] impl crate::server::Handler for DirHandler { type Reader = Unblock; type Writer = Unblock; diff --git a/src/tests/handlers.rs b/src/tests/handlers.rs index 6be858a..00adf62 100644 --- a/src/tests/handlers.rs +++ b/src/tests/handlers.rs @@ -24,7 +24,6 @@ impl RandomHandler { } } -#[crate::async_trait] impl Handler for RandomHandler { type Reader = RandomFile; type Writer = Sink;