From a50837f21e2da46cceca6c745600a754a787f92f Mon Sep 17 00:00:00 2001 From: veeso Date: Thu, 7 Sep 2023 15:49:19 +0200 Subject: [PATCH] fmt --- rustfmt.toml | 2 ++ suppaftp-cli/src/actions.rs | 5 +-- suppaftp-cli/src/command.rs | 1 + suppaftp-cli/src/main.rs | 8 ++--- suppaftp/src/async_ftp/data_stream.rs | 3 +- suppaftp/src/async_ftp/mod.rs | 45 ++++++++++++------------ suppaftp/src/async_ftp/tls.rs | 3 +- suppaftp/src/async_ftp/tls/native_tls.rs | 9 +++-- suppaftp/src/async_ftp/tls/rustls.rs | 12 +++---- suppaftp/src/command.rs | 9 ++--- suppaftp/src/lib.rs | 7 ++-- suppaftp/src/list.rs | 11 +++--- suppaftp/src/regex.rs | 4 +-- suppaftp/src/status.rs | 4 +-- suppaftp/src/sync_ftp/data_stream.rs | 4 +-- suppaftp/src/sync_ftp/mod.rs | 34 +++++++++--------- suppaftp/src/sync_ftp/tls.rs | 7 ++-- suppaftp/src/sync_ftp/tls/native_tls.rs | 3 +- suppaftp/src/sync_ftp/tls/rustls.rs | 6 ++-- suppaftp/src/types.rs | 8 +++-- 20 files changed, 96 insertions(+), 89 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..64d94de --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +group_imports = "StdExternalCrate" +imports_granularity = "Module" diff --git a/suppaftp-cli/src/actions.rs b/suppaftp-cli/src/actions.rs index 71b51bc..95c26c6 100644 --- a/suppaftp-cli/src/actions.rs +++ b/suppaftp-cli/src/actions.rs @@ -1,12 +1,13 @@ -use super::{FtpError, FtpStream}; - use std::fs::File; use std::io; use std::path::Path; + use suppaftp::native_tls::TlsConnector; use suppaftp::types::FileType; use suppaftp::{Mode, NativeTlsConnector}; +use super::{FtpError, FtpStream}; + pub fn quit(mut ftp: Option) { if let Some(mut ftp) = ftp.take() { match ftp.quit() { diff --git a/suppaftp-cli/src/command.rs b/suppaftp-cli/src/command.rs index 5b3dc23..bca4379 100644 --- a/suppaftp-cli/src/command.rs +++ b/suppaftp-cli/src/command.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; use std::str::FromStr; + use suppaftp::Mode; pub enum Command { diff --git a/suppaftp-cli/src/main.rs b/suppaftp-cli/src/main.rs index 8b5b360..31b6161 100644 --- a/suppaftp-cli/src/main.rs +++ b/suppaftp-cli/src/main.rs @@ -8,15 +8,15 @@ mod actions; mod args; mod command; +use std::io; +use std::io::Write; +use std::str::FromStr; + use actions::*; use args::Args; use command::Command; - use env_logger::Builder as LogBuilder; use log::LevelFilter; -use std::io; -use std::io::Write; -use std::str::FromStr; use suppaftp::{FtpError, NativeTlsFtpStream as FtpStream}; const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/suppaftp/src/async_ftp/data_stream.rs b/suppaftp/src/async_ftp/data_stream.rs index 8ed63cc..438c185 100644 --- a/suppaftp/src/async_ftp/data_stream.rs +++ b/suppaftp/src/async_ftp/data_stream.rs @@ -2,12 +2,13 @@ //! //! This module exposes the async data stream implementation where bytes must be written to/read from +use std::pin::Pin; + #[cfg(any(feature = "async", feature = "async-secure"))] use async_std::io::{Read, Result, Write}; #[cfg(any(feature = "async", feature = "async-secure"))] use async_std::net::TcpStream; use pin_project::pin_project; -use std::pin::Pin; use super::AsyncTlsStream; diff --git a/suppaftp/src/async_ftp/mod.rs b/suppaftp/src/async_ftp/mod.rs index c3020bf..399f37d 100644 --- a/suppaftp/src/async_ftp/mod.rs +++ b/suppaftp/src/async_ftp/mod.rs @@ -5,35 +5,35 @@ mod data_stream; mod tls; -use super::regex::{EPSV_PORT_RE, MDTM_RE, PASV_PORT_RE, SIZE_RE}; -use super::types::{FileType, FtpError, FtpResult, Mode, Response}; -use super::Status; -use crate::command::Command; -#[cfg(feature = "async-secure")] -use crate::command::ProtectionLevel; -use crate::types::Features; -use async_std::io::prelude::BufReadExt; -use tls::AsyncTlsStream; - -use async_std::io::{copy, BufReader, Read, Write, WriteExt}; -use async_std::net::{TcpListener, TcpStream, ToSocketAddrs}; -use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; #[cfg(not(feature = "async-secure"))] use std::marker::PhantomData; use std::net::{Ipv4Addr, SocketAddr}; use std::string::String; use std::time::Duration; +use async_std::io::prelude::BufReadExt; +use async_std::io::{copy, BufReader, Read, Write, WriteExt}; +use async_std::net::{TcpListener, TcpStream, ToSocketAddrs}; +use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; // export pub use data_stream::DataStream; pub use tls::AsyncNoTlsStream; #[cfg(feature = "async-secure")] pub use tls::AsyncTlsConnector; +use tls::AsyncTlsStream; #[cfg(feature = "async-native-tls")] pub use tls::{AsyncNativeTlsConnector, AsyncNativeTlsStream}; #[cfg(feature = "async-rustls")] pub use tls::{AsyncRustlsConnector, AsyncRustlsStream}; +use super::regex::{EPSV_PORT_RE, MDTM_RE, PASV_PORT_RE, SIZE_RE}; +use super::types::{FileType, FtpError, FtpResult, Mode, Response}; +use super::Status; +use crate::command::Command; +#[cfg(feature = "async-secure")] +use crate::command::ProtectionLevel; +use crate::types::Features; + /// Stream to interface with the FTP server. This interface is only for the command stream. pub struct ImplAsyncFtpStream where @@ -920,15 +920,6 @@ where #[cfg(test)] mod test { - use super::*; - #[cfg(feature = "with-containers")] - use crate::types::FormatControl; - use crate::AsyncFtpStream; - - #[cfg(feature = "async-native-tls")] - use crate::{AsyncNativeTlsConnector, AsyncNativeTlsFtpStream}; - #[cfg(feature = "async-rustls")] - use crate::{AsyncRustlsConnector, AsyncRustlsFtpStream}; #[cfg(feature = "async-native-tls")] use async_native_tls::TlsConnector as NativeTlsConnector; #[cfg(feature = "async-rustls")] @@ -937,9 +928,17 @@ mod test { use pretty_assertions::assert_eq; #[cfg(feature = "with-containers")] use rand::{distributions::Alphanumeric, thread_rng, Rng}; - use serial_test::serial; + use super::*; + #[cfg(feature = "with-containers")] + use crate::types::FormatControl; + use crate::AsyncFtpStream; + #[cfg(feature = "async-native-tls")] + use crate::{AsyncNativeTlsConnector, AsyncNativeTlsFtpStream}; + #[cfg(feature = "async-rustls")] + use crate::{AsyncRustlsConnector, AsyncRustlsFtpStream}; + #[cfg(feature = "with-containers")] #[async_attributes::test] #[serial] diff --git a/suppaftp/src/async_ftp/tls.rs b/suppaftp/src/async_ftp/tls.rs index 7bed758..5f4bf51 100644 --- a/suppaftp/src/async_ftp/tls.rs +++ b/suppaftp/src/async_ftp/tls.rs @@ -2,10 +2,11 @@ //! //! Tls wrappers +use std::fmt::Debug; + use async_std::io::{Read, Write}; use async_std::net::TcpStream; use async_trait::async_trait; -use std::fmt::Debug; use crate::FtpResult; diff --git a/suppaftp/src/async_ftp/tls/native_tls.rs b/suppaftp/src/async_ftp/tls/native_tls.rs index f122cb3..35ce8ee 100644 --- a/suppaftp/src/async_ftp/tls/native_tls.rs +++ b/suppaftp/src/async_ftp/tls/native_tls.rs @@ -2,14 +2,13 @@ //! //! Native tls types for suppaftp +use std::pin::Pin; + use async_native_tls::{TlsConnector, TlsStream}; -use async_std::{ - io::{Read, Write}, - net::TcpStream, -}; +use async_std::io::{Read, Write}; +use async_std::net::TcpStream; use async_trait::async_trait; use pin_project::pin_project; -use std::pin::Pin; use super::{AsyncTlsConnector, AsyncTlsStream}; use crate::{FtpError, FtpResult}; diff --git a/suppaftp/src/async_ftp/tls/rustls.rs b/suppaftp/src/async_ftp/tls/rustls.rs index 8c85110..78e9f7a 100644 --- a/suppaftp/src/async_ftp/tls/rustls.rs +++ b/suppaftp/src/async_ftp/tls/rustls.rs @@ -2,14 +2,14 @@ //! //! rustls types for suppaftp -use async_std::{ - io::{Read, Write}, - net::TcpStream, -}; -use async_tls::{client::TlsStream, TlsConnector as RustlsTlsConnector}; +use std::pin::Pin; + +use async_std::io::{Read, Write}; +use async_std::net::TcpStream; +use async_tls::client::TlsStream; +use async_tls::TlsConnector as RustlsTlsConnector; use async_trait::async_trait; use pin_project::pin_project; -use std::pin::Pin; use super::{AsyncTlsConnector, AsyncTlsStream}; use crate::{FtpError, FtpResult}; diff --git a/suppaftp/src/command.rs b/suppaftp/src/command.rs index df1cc65..5a0462d 100644 --- a/suppaftp/src/command.rs +++ b/suppaftp/src/command.rs @@ -2,9 +2,10 @@ //! //! The set of FTP commands -use crate::types::FileType; +use std::net::SocketAddr; +use std::string::ToString; -use std::{net::SocketAddr, string::ToString}; +use crate::types::FileType; #[derive(Debug, Clone, PartialEq, Eq)] /// Ftp commands with their arguments @@ -171,10 +172,10 @@ impl ToString for ProtectionLevel { #[cfg(test)] mod test { - use super::*; - use pretty_assertions::assert_eq; + use super::*; + #[test] fn should_stringify_command() { assert_eq!(Command::Abor.to_string().as_str(), "ABOR\r\n"); diff --git a/suppaftp/src/lib.rs b/suppaftp/src/lib.rs index b91338b..4ddca65 100644 --- a/suppaftp/src/lib.rs +++ b/suppaftp/src/lib.rs @@ -153,11 +153,10 @@ pub extern crate async_native_tls_crate as async_native_tls; // -- export (common) pub use status::Status; -pub use types::{FtpError, FtpResult, Mode}; - // -- export sync pub use sync_ftp::ImplFtpStream; use sync_ftp::NoTlsStream; +pub use types::{FtpError, FtpResult, Mode}; pub type FtpStream = ImplFtpStream; pub use sync_ftp::DataStream; // -- export secure (native-tls) @@ -182,13 +181,13 @@ use async_ftp::AsyncNoTlsStream; pub use async_ftp::ImplAsyncFtpStream; #[cfg(feature = "async")] pub type AsyncFtpStream = ImplAsyncFtpStream; -#[cfg(feature = "async")] -pub use async_ftp::DataStream as AsyncDataStream; // -- export async secure (native-tls) #[cfg(feature = "async-native-tls")] pub use async_ftp::AsyncNativeTlsConnector; #[cfg(feature = "async-native-tls")] use async_ftp::AsyncNativeTlsStream; +#[cfg(feature = "async")] +pub use async_ftp::DataStream as AsyncDataStream; #[cfg(feature = "async-native-tls")] pub type AsyncNativeTlsFtpStream = ImplAsyncFtpStream; // -- export async secure (rustls) diff --git a/suppaftp/src/list.rs b/suppaftp/src/list.rs index 3f52da9..ad1f68d 100644 --- a/suppaftp/src/list.rs +++ b/suppaftp/src/list.rs @@ -32,14 +32,15 @@ //! //! ``` -use chrono::prelude::{NaiveDate, NaiveDateTime, Utc}; -use chrono::Datelike; -use lazy_regex::{Lazy, Regex}; use std::convert::TryFrom; use std::ops::Range; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::time::{Duration, SystemTime}; + +use chrono::prelude::{NaiveDate, NaiveDateTime, Utc}; +use chrono::Datelike; +use lazy_regex::{Lazy, Regex}; use thiserror::Error; // -- Regex @@ -494,11 +495,11 @@ impl From for PosixPex { #[cfg(test)] mod test { - use super::*; - use chrono::DateTime; use pretty_assertions::assert_eq; + use super::*; + #[test] fn file_getters() { let file: File = File { diff --git a/suppaftp/src/regex.rs b/suppaftp/src/regex.rs index 5838329..6956f72 100644 --- a/suppaftp/src/regex.rs +++ b/suppaftp/src/regex.rs @@ -21,10 +21,10 @@ pub static SIZE_RE: Lazy = lazy_regex!(r"\s+(\d+)\s*$"); #[cfg(test)] mod test { - use super::*; - use pretty_assertions::assert_eq; + use super::*; + #[test] fn should_match_pasv_port() { let response = "227 Entering Passive Mode (213,229,112,130,216,4)"; diff --git a/suppaftp/src/status.rs b/suppaftp/src/status.rs index 0864079..1f2092d 100644 --- a/suppaftp/src/status.rs +++ b/suppaftp/src/status.rs @@ -180,10 +180,10 @@ impl From for Status { #[cfg(test)] mod test { - use super::*; - use pretty_assertions::assert_eq; + use super::*; + #[test] fn should_return_code_for_status() { assert_eq!(Status::BadFilename.code(), 553); diff --git a/suppaftp/src/sync_ftp/data_stream.rs b/suppaftp/src/sync_ftp/data_stream.rs index 05483b8..c314aa0 100644 --- a/suppaftp/src/sync_ftp/data_stream.rs +++ b/suppaftp/src/sync_ftp/data_stream.rs @@ -2,11 +2,11 @@ //! //! This module exposes the data stream where bytes must be written to/read from -use super::tls::TlsStream; - use std::io::{Read, Result, Write}; use std::net::TcpStream; +use super::tls::TlsStream; + /// Data Stream used for communications. It can be both of type Tcp in case of plain communication or Ssl in case of FTPS #[derive(Debug)] pub enum DataStream diff --git a/suppaftp/src/sync_ftp/mod.rs b/suppaftp/src/sync_ftp/mod.rs index 9f1877e..68427d3 100644 --- a/suppaftp/src/sync_ftp/mod.rs +++ b/suppaftp/src/sync_ftp/mod.rs @@ -5,16 +5,6 @@ mod data_stream; mod tls; -use super::regex::{EPSV_PORT_RE, MDTM_RE, PASV_PORT_RE, SIZE_RE}; -use super::types::{FileType, FtpError, FtpResult, Mode, Response}; -use super::Status; -use crate::command::Command; -#[cfg(feature = "secure")] -use crate::command::ProtectionLevel; -use crate::types::Features; -use tls::TlsStream; - -use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use std::fmt::Debug; use std::io::{copy, BufRead, BufReader, Cursor, Read, Write}; #[cfg(not(feature = "secure"))] @@ -22,16 +12,26 @@ use std::marker::PhantomData; use std::net::{Ipv4Addr, SocketAddr, TcpListener, TcpStream, ToSocketAddrs}; use std::time::Duration; +use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; // export pub use data_stream::DataStream; pub use tls::NoTlsStream; #[cfg(feature = "secure")] pub use tls::TlsConnector; +use tls::TlsStream; #[cfg(feature = "native-tls")] pub use tls::{NativeTlsConnector, NativeTlsStream}; #[cfg(feature = "rustls")] pub use tls::{RustlsConnector, RustlsStream}; +use super::regex::{EPSV_PORT_RE, MDTM_RE, PASV_PORT_RE, SIZE_RE}; +use super::types::{FileType, FtpError, FtpResult, Mode, Response}; +use super::Status; +use crate::command::Command; +#[cfg(feature = "secure")] +use crate::command::ProtectionLevel; +use crate::types::Features; + /// Stream to interface with the FTP server. This interface is only for the command stream. #[derive(Debug)] pub struct ImplFtpStream @@ -914,11 +914,8 @@ where #[cfg(test)] mod test { - use super::*; - use crate::FtpStream; - - #[cfg(feature = "with-containers")] - use crate::types::FormatControl; + #[cfg(feature = "rustls")] + use std::sync::Arc; #[cfg(feature = "native-tls")] use native_tls::TlsConnector; @@ -929,8 +926,11 @@ mod test { #[cfg(feature = "rustls")] use rustls::ClientConfig; use serial_test::serial; - #[cfg(feature = "rustls")] - use std::sync::Arc; + + use super::*; + #[cfg(feature = "with-containers")] + use crate::types::FormatControl; + use crate::FtpStream; #[test] #[cfg(feature = "with-containers")] diff --git a/suppaftp/src/sync_ftp/tls.rs b/suppaftp/src/sync_ftp/tls.rs index 47de45c..9221768 100644 --- a/suppaftp/src/sync_ftp/tls.rs +++ b/suppaftp/src/sync_ftp/tls.rs @@ -2,16 +2,15 @@ //! //! Tls wrappers -use std::io::Write; +use std::fmt::Debug; +use std::io::{Read, Write}; use std::net::TcpStream; -use std::{fmt::Debug, io::Read}; #[cfg(feature = "native-tls")] mod native_tls; -use crate::FtpResult; - #[cfg(feature = "native-tls")] pub use self::native_tls::{NativeTlsConnector, NativeTlsStream}; +use crate::FtpResult; #[cfg(feature = "rustls")] mod rustls; diff --git a/suppaftp/src/sync_ftp/tls/native_tls.rs b/suppaftp/src/sync_ftp/tls/native_tls.rs index e9d5724..50e3a0f 100644 --- a/suppaftp/src/sync_ftp/tls/native_tls.rs +++ b/suppaftp/src/sync_ftp/tls/native_tls.rs @@ -2,10 +2,11 @@ //! //! Native tls implementation of TLS types -use native_tls_crate::{TlsConnector, TlsStream}; use std::io::Write; use std::net::TcpStream; +use native_tls_crate::{TlsConnector, TlsStream}; + use super::{TlsConnector as TlsConnectorTrait, TlsStream as TlsStreamTrait}; use crate::{FtpError, FtpResult}; diff --git a/suppaftp/src/sync_ftp/tls/rustls.rs b/suppaftp/src/sync_ftp/tls/rustls.rs index 08be499..f630371 100644 --- a/suppaftp/src/sync_ftp/tls/rustls.rs +++ b/suppaftp/src/sync_ftp/tls/rustls.rs @@ -2,14 +2,14 @@ //! //! Rustls implementation of tls types -use crate::{FtpError, FtpResult}; - -use rustls::{ClientConfig, ClientConnection, ServerName, StreamOwned}; use std::io::Write; use std::net::TcpStream; use std::sync::Arc; +use rustls::{ClientConfig, ClientConnection, ServerName, StreamOwned}; + use super::{TlsConnector, TlsStream}; +use crate::{FtpError, FtpResult}; /// A Wrapper for the tls connector pub struct RustlsConnector { diff --git a/suppaftp/src/types.rs b/suppaftp/src/types.rs index db2fa5e..49d46db 100644 --- a/suppaftp/src/types.rs +++ b/suppaftp/src/types.rs @@ -2,13 +2,15 @@ //! //! The set of valid values for FTP commands -use super::Status; use std::collections::HashMap; use std::convert::From; use std::fmt; use std::string::FromUtf8Error; + use thiserror::Error; +use super::Status; + /// A shorthand for a Result whose error type is always an FtpError. pub type FtpResult = std::result::Result; @@ -130,10 +132,10 @@ impl ToString for FileType { #[cfg(test)] mod test { - use super::*; - use pretty_assertions::assert_eq; + use super::*; + #[test] fn fmt_error() { assert_eq!(