Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Sep 7, 2023
1 parent 0d6328c commit a50837f
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 89 deletions.
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group_imports = "StdExternalCrate"
imports_granularity = "Module"
5 changes: 3 additions & 2 deletions suppaftp-cli/src/actions.rs
Original file line number Diff line number Diff line change
@@ -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<FtpStream>) {
if let Some(mut ftp) = ftp.take() {
match ftp.quit() {
Expand Down
1 change: 1 addition & 0 deletions suppaftp-cli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::PathBuf;
use std::str::FromStr;

use suppaftp::Mode;

pub enum Command {
Expand Down
8 changes: 4 additions & 4 deletions suppaftp-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion suppaftp/src/async_ftp/data_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
45 changes: 22 additions & 23 deletions suppaftp/src/async_ftp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
where
Expand Down Expand Up @@ -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")]
Expand All @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion suppaftp/src/async_ftp/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 4 additions & 5 deletions suppaftp/src/async_ftp/tls/native_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
12 changes: 6 additions & 6 deletions suppaftp/src/async_ftp/tls/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
9 changes: 5 additions & 4 deletions suppaftp/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
7 changes: 3 additions & 4 deletions suppaftp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NoTlsStream>;
pub use sync_ftp::DataStream;
// -- export secure (native-tls)
Expand All @@ -182,13 +181,13 @@ use async_ftp::AsyncNoTlsStream;
pub use async_ftp::ImplAsyncFtpStream;
#[cfg(feature = "async")]
pub type AsyncFtpStream = ImplAsyncFtpStream<AsyncNoTlsStream>;
#[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<AsyncNativeTlsStream>;
// -- export async secure (rustls)
Expand Down
11 changes: 6 additions & 5 deletions suppaftp/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -494,11 +495,11 @@ impl From<u8> 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 {
Expand Down
4 changes: 2 additions & 2 deletions suppaftp/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub static SIZE_RE: Lazy<Regex> = 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)";
Expand Down
4 changes: 2 additions & 2 deletions suppaftp/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ impl From<u32> 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);
Expand Down
4 changes: 2 additions & 2 deletions suppaftp/src/sync_ftp/data_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
Expand Down
34 changes: 17 additions & 17 deletions suppaftp/src/sync_ftp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
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"))]
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<T>
Expand Down Expand Up @@ -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;
Expand All @@ -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")]
Expand Down
Loading

0 comments on commit a50837f

Please sign in to comment.