Skip to content

Commit 60b57f7

Browse files
committed
make async-trait as optional
1 parent 26286c0 commit 60b57f7

File tree

12 files changed

+22
-44
lines changed

12 files changed

+22
-44
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ repository = "https://github.com/ssrlive/socks5-impl"
1515
client = ["tokio"]
1616
serde = ["dep:serde"]
1717
server = ["tokio"]
18-
tokio = ["dep:tokio"]
18+
tokio = ["dep:tokio", "async-trait"]
1919

2020
[dependencies]
21-
async-trait = "0.1"
21+
async-trait = { version = "0.1", optional = true }
2222
bytes = "1"
2323
percent-encoding = "2"
2424
serde = { version = "1", features = ["derive"], optional = true }

src/client/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::{
22
error::{Error, Result},
33
protocol::{Address, AddressType, AsyncStreamOperation, AuthMethod, Command, Reply, StreamOperation, UserKey, Version},
44
};
5-
use async_trait::async_trait;
65
use std::{
76
fmt::Debug,
87
io::Cursor,
@@ -14,7 +13,7 @@ use tokio::{
1413
net::{TcpStream, UdpSocket},
1514
};
1615

17-
#[async_trait]
16+
#[async_trait::async_trait]
1817
pub trait Socks5Reader: AsyncReadExt + Unpin {
1918
async fn read_version(&mut self) -> Result<()> {
2019
let value = Version::try_from(self.read_u8().await?)?;
@@ -109,10 +108,10 @@ pub trait Socks5Reader: AsyncReadExt + Unpin {
109108
}
110109
}
111110

112-
#[async_trait]
111+
#[async_trait::async_trait]
113112
impl<T: AsyncReadExt + Unpin> Socks5Reader for T {}
114113

115-
#[async_trait]
114+
#[async_trait::async_trait]
116115
pub trait Socks5Writer: AsyncWriteExt + Unpin {
117116
async fn write_version(&mut self) -> Result<()> {
118117
self.write_u8(0x05).await?;
@@ -189,7 +188,7 @@ pub trait Socks5Writer: AsyncWriteExt + Unpin {
189188
}
190189
}
191190

192-
#[async_trait]
191+
#[async_trait::async_trait]
193192
impl<T: AsyncWriteExt + Unpin> Socks5Writer for T {}
194193

195194
async fn username_password_auth<S>(stream: &mut S, auth: &UserKey) -> Result<()>
@@ -426,7 +425,7 @@ where
426425
pub type GuardTcpStream = BufStream<TcpStream>;
427426
pub type SocksUdpClient = SocksDatagram<GuardTcpStream>;
428427

429-
#[async_trait]
428+
#[async_trait::async_trait]
430429
pub trait UdpClientTrait {
431430
async fn send_to<A>(&mut self, buf: &[u8], addr: A) -> Result<usize>
432431
where
@@ -435,7 +434,7 @@ pub trait UdpClientTrait {
435434
async fn recv_from(&mut self, timeout: Duration, buf: &mut Vec<u8>) -> Result<(usize, Address)>;
436435
}
437436

438-
#[async_trait]
437+
#[async_trait::async_trait]
439438
impl UdpClientTrait for SocksUdpClient {
440439
async fn send_to<A>(&mut self, buf: &[u8], addr: A) -> Result<usize, Error>
441440
where
@@ -494,7 +493,6 @@ mod tests {
494493
client::{self, SocksListener, SocksUdpClient, UdpClientTrait},
495494
protocol::{Address, UserKey},
496495
};
497-
use async_trait::async_trait;
498496
use std::{
499497
net::{SocketAddr, ToSocketAddrs},
500498
sync::Arc,
@@ -563,7 +561,7 @@ mod tests {
563561

564562
type TestHalves = (Arc<SocksUdpClient>, Arc<SocksUdpClient>);
565563

566-
#[async_trait]
564+
#[async_trait::async_trait]
567565
impl UdpClientTrait for TestHalves {
568566
async fn send_to<A>(&mut self, buf: &[u8], addr: A) -> Result<usize, Error>
569567
where

src/protocol/address.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#[cfg(feature = "tokio")]
22
use crate::protocol::AsyncStreamOperation;
33
use crate::protocol::StreamOperation;
4-
#[cfg(feature = "tokio")]
5-
use async_trait::async_trait;
64
use bytes::BufMut;
75
use std::{
86
io::Cursor,
@@ -164,7 +162,7 @@ impl StreamOperation for Address {
164162
}
165163

166164
#[cfg(feature = "tokio")]
167-
#[async_trait]
165+
#[async_trait::async_trait]
168166
impl AsyncStreamOperation for Address {
169167
async fn retrieve_from_async_stream<R>(stream: &mut R) -> std::io::Result<Self>
170168
where

src/protocol/handshake/password_method/request.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
use crate::protocol::AsyncStreamOperation;
33
use crate::protocol::{StreamOperation, UserKey};
44
#[cfg(feature = "tokio")]
5-
use async_trait::async_trait;
6-
#[cfg(feature = "tokio")]
75
use tokio::io::{AsyncRead, AsyncReadExt};
86

97
/// SOCKS5 password handshake request
@@ -75,7 +73,7 @@ impl StreamOperation for Request {
7573
}
7674

7775
#[cfg(feature = "tokio")]
78-
#[async_trait]
76+
#[async_trait::async_trait]
7977
impl AsyncStreamOperation for Request {
8078
async fn retrieve_from_async_stream<R>(r: &mut R) -> std::io::Result<Self>
8179
where

src/protocol/handshake/password_method/response.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
use crate::protocol::AsyncStreamOperation;
33
use crate::protocol::StreamOperation;
44
#[cfg(feature = "tokio")]
5-
use async_trait::async_trait;
6-
#[cfg(feature = "tokio")]
75
use tokio::io::{AsyncRead, AsyncReadExt};
86

97
#[repr(u8)]
@@ -90,7 +88,7 @@ impl StreamOperation for Response {
9088
}
9189

9290
#[cfg(feature = "tokio")]
93-
#[async_trait]
91+
#[async_trait::async_trait]
9492
impl AsyncStreamOperation for Response {
9593
async fn retrieve_from_async_stream<R>(r: &mut R) -> std::io::Result<Self>
9694
where

src/protocol/handshake/request.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
use crate::protocol::AsyncStreamOperation;
33
use crate::protocol::{AuthMethod, StreamOperation, Version};
44
#[cfg(feature = "tokio")]
5-
use async_trait::async_trait;
6-
#[cfg(feature = "tokio")]
75
use tokio::io::{AsyncRead, AsyncReadExt};
86

97
/// SOCKS5 handshake request
@@ -67,7 +65,7 @@ impl StreamOperation for Request {
6765
}
6866

6967
#[cfg(feature = "tokio")]
70-
#[async_trait]
68+
#[async_trait::async_trait]
7169
impl AsyncStreamOperation for Request {
7270
async fn retrieve_from_async_stream<R>(r: &mut R) -> std::io::Result<Self>
7371
where

src/protocol/handshake/response.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
use crate::protocol::AsyncStreamOperation;
33
use crate::protocol::{AuthMethod, StreamOperation, Version};
44
#[cfg(feature = "tokio")]
5-
use async_trait::async_trait;
6-
#[cfg(feature = "tokio")]
75
use tokio::io::{AsyncRead, AsyncReadExt};
86

97
/// SOCKS5 handshake response
@@ -55,7 +53,7 @@ impl StreamOperation for Response {
5553
}
5654

5755
#[cfg(feature = "tokio")]
58-
#[async_trait]
56+
#[async_trait::async_trait]
5957
impl AsyncStreamOperation for Response {
6058
async fn retrieve_from_async_stream<R>(r: &mut R) -> std::io::Result<Self>
6159
where

src/protocol/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ pub use self::{
2020
};
2121
pub use bytes::BufMut;
2222

23-
#[cfg(feature = "tokio")]
24-
use async_trait::async_trait;
2523
#[cfg(feature = "tokio")]
2624
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
2725

@@ -81,7 +79,7 @@ pub trait StreamOperation {
8179
}
8280

8381
#[cfg(feature = "tokio")]
84-
#[async_trait]
82+
#[async_trait::async_trait]
8583
pub trait AsyncStreamOperation: StreamOperation {
8684
async fn retrieve_from_async_stream<R>(r: &mut R) -> std::io::Result<Self>
8785
where

src/protocol/request.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
use crate::protocol::AsyncStreamOperation;
33
use crate::protocol::{Address, Command, StreamOperation, Version};
44
#[cfg(feature = "tokio")]
5-
use async_trait::async_trait;
6-
#[cfg(feature = "tokio")]
75
use tokio::io::{AsyncRead, AsyncReadExt};
86

97
/// SOCKS5 request
@@ -60,7 +58,7 @@ impl StreamOperation for Request {
6058
}
6159

6260
#[cfg(feature = "tokio")]
63-
#[async_trait]
61+
#[async_trait::async_trait]
6462
impl AsyncStreamOperation for Request {
6563
async fn retrieve_from_async_stream<R>(r: &mut R) -> std::io::Result<Self>
6664
where

src/protocol/response.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
use crate::protocol::AsyncStreamOperation;
33
use crate::protocol::{Address, Reply, StreamOperation, Version};
44
#[cfg(feature = "tokio")]
5-
use async_trait::async_trait;
6-
#[cfg(feature = "tokio")]
75
use tokio::io::{AsyncRead, AsyncReadExt};
86

97
/// Response
@@ -60,7 +58,7 @@ impl StreamOperation for Response {
6058
}
6159

6260
#[cfg(feature = "tokio")]
63-
#[async_trait]
61+
#[async_trait::async_trait]
6462
impl AsyncStreamOperation for Response {
6563
async fn retrieve_from_async_stream<R>(r: &mut R) -> std::io::Result<Self>
6664
where

0 commit comments

Comments
 (0)