Skip to content

Commit

Permalink
feat!: Use RTITIT instead of async-trait
Browse files Browse the repository at this point in the history
  • Loading branch information
oblique committed Apr 25, 2024
1 parent dd82faa commit dbe377a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = "async-tftp"
version = "0.3.6"
authors = ["oblique <[email protected]>"]
edition = "2018"
edition = "2021"
rust-version = "1.75"
license = "MIT"
readme = "README.md"

Expand All @@ -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"

Expand Down
1 change: 0 additions & 1 deletion examples/tftpd-targz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Archive<GzipDecoder<BufReader<File>>>>;
type Writer = Sink;
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 6 additions & 5 deletions src/server/handler.rs
Original file line number Diff line number Diff line change
@@ -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<u64>), packet::Error>;
) -> impl Future<Output = Result<(Self::Reader, Option<u64>), 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<u64>,
) -> Result<Self::Writer, packet::Error>;
) -> impl Future<Output = Result<Self::Writer, packet::Error>> + Send;
}
1 change: 0 additions & 1 deletion src/server/handlers/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl DirHandler {
}
}

#[crate::async_trait]
impl crate::server::Handler for DirHandler {
type Reader = Unblock<File>;
type Writer = Unblock<File>;
Expand Down
1 change: 0 additions & 1 deletion src/tests/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ impl RandomHandler {
}
}

#[crate::async_trait]
impl Handler for RandomHandler {
type Reader = RandomFile;
type Writer = Sink;
Expand Down

0 comments on commit dbe377a

Please sign in to comment.