Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group imports with StdExternalCrate #57

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use_small_heuristics = "Default"
hard_tabs = false
imports_layout = "HorizontalVertical"
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
match_block_trailing_comma = true
max_width = 120
newline_style = "Unix"
Expand Down
8 changes: 5 additions & 3 deletions src/io/compat/futures.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use super::Compat;
use crate::io::AsyncSocket;
use futures_io::{AsyncRead, AsyncWrite};
use std::{
io::Result as IoResult,
pin::Pin,
task::{Context, Poll},
};

use futures_io::{AsyncRead, AsyncWrite};

use super::Compat;
use crate::io::AsyncSocket;

impl<S> AsyncSocket for Compat<S>
where S: AsyncRead + AsyncWrite + Unpin
{
Expand Down
3 changes: 2 additions & 1 deletion src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[cfg(feature = "tokio")]
mod tokio;

use futures_util::ready;
use std::{
future::Future,
io::{Error, ErrorKind},
Expand All @@ -12,6 +11,8 @@ use std::{
task::{Context, Poll},
};

use futures_util::ready;

#[cfg(feature = "futures-io")]
mod compat;
#[cfg(feature = "futures-io")]
Expand Down
6 changes: 4 additions & 2 deletions src/io/tokio.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//! AsyncSocket trait implementation for tokio's AsyncRead + AsyncWrite
//! traits.
use super::AsyncSocket;
use futures_util::ready;
use std::{
io::Result as IoResult,
pin::Pin,
task::{Context, Poll},
};

use futures_util::ready;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

use super::AsyncSocket;

impl<S> AsyncSocket for S
where S: AsyncRead + AsyncWrite
{
Expand Down
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use either::Either;
use futures_util::{
future,
stream::{self, Once, Stream},
};
use std::{
borrow::Cow,
io::Result as IoResult,
Expand All @@ -12,7 +7,12 @@ use std::{
vec,
};

use either::Either;
pub use error::Error;
use futures_util::{
future,
stream::{self, Once, Stream},
};

pub type Result<T> = std::result::Result<T, Error>;

Expand Down Expand Up @@ -265,10 +265,11 @@ pub mod tcp;

#[cfg(test)]
mod tests {
use super::*;
use futures_executor::block_on;
use futures_util::StreamExt;

use super::*;

fn to_proxy_addrs<T: ToProxyAddrs>(t: T) -> Result<Vec<SocketAddr>> {
Ok(block_on(t.to_proxy_addrs().map(Result::unwrap).collect()))
}
Expand Down
22 changes: 11 additions & 11 deletions src/tcp/socks4.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
use crate::{
io::{AsyncSocket, AsyncSocketExt},
Error,
IntoTargetAddr,
Result,
TargetAddr,
};

use futures_util::stream::{self, Fuse, Stream, StreamExt};
use std::{
borrow::Borrow,
io,
Expand All @@ -16,11 +7,20 @@ use std::{
task::{Context, Poll},
};

#[cfg(feature = "tokio")]
use crate::ToProxyAddrs;
use futures_util::stream::{self, Fuse, Stream, StreamExt};
#[cfg(feature = "tokio")]
use tokio::net::TcpStream;

#[cfg(feature = "tokio")]
use crate::ToProxyAddrs;
use crate::{
io::{AsyncSocket, AsyncSocketExt},
Error,
IntoTargetAddr,
Result,
TargetAddr,
};

#[repr(u8)]
#[derive(Clone, Copy)]
enum CommandV4 {
Expand Down
21 changes: 10 additions & 11 deletions src/tcp/socks5.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
use crate::{
io::{AsyncSocket, AsyncSocketExt},
Authentication,
Error,
IntoTargetAddr,
Result,
TargetAddr,
};

use std::{
borrow::Borrow,
io,
Expand All @@ -17,11 +8,19 @@ use std::{
};

use futures_util::stream::{self, Fuse, Stream, StreamExt};
#[cfg(feature = "tokio")]
use tokio::net::TcpStream;

#[cfg(feature = "tokio")]
use crate::ToProxyAddrs;
#[cfg(feature = "tokio")]
use tokio::net::TcpStream;
use crate::{
io::{AsyncSocket, AsyncSocketExt},
Authentication,
Error,
IntoTargetAddr,
Result,
TargetAddr,
};

#[repr(u8)]
#[derive(Clone, Copy)]
Expand Down
10 changes: 6 additions & 4 deletions tests/common/futures_utils.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use super::*;
use futures_util::{io::copy, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use once_cell::sync::OnceCell;
use smol::net::{unix::UnixStream, TcpListener};
use std::{
future::Future,
io::{Read, Write},
net::{SocketAddr, TcpStream as StdTcpStream},
sync::Mutex,
};

use futures_util::{io::copy, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use once_cell::sync::OnceCell;
use smol::net::{unix::UnixStream, TcpListener};
use tokio_socks::{
io::Compat,
tcp::{socks4::Socks4Listener, socks5::Socks5Listener},
Error,
Result,
};

use super::*;

pub async fn echo_server() -> Result<()> {
let listener = TcpListener::bind(&SocketAddr::from(([0, 0, 0, 0], 10007))).await?;
loop {
Expand Down
6 changes: 4 additions & 2 deletions tests/common/tokio_utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::*;
use once_cell::sync::OnceCell;
use std::{
io::{Read, Write},
net::{SocketAddr, TcpStream as StdTcpStream},
sync::Mutex,
};

use once_cell::sync::OnceCell;
use tokio::{
io::{copy, split, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt},
net::{TcpListener, UnixStream},
Expand All @@ -16,6 +16,8 @@ use tokio_socks::{
Result,
};

use super::*;

pub async fn echo_server() -> Result<()> {
let listener = TcpListener::bind(&SocketAddr::from(([0, 0, 0, 0], 10007))).await?;
loop {
Expand Down