From 27b6970edae5a4a6156e32ba49f05ad8f45aedae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20M=2E=20Bezerra?= Date: Tue, 2 Nov 2021 16:15:36 -0300 Subject: [PATCH] Updating rustfmt --- build.rs | 4 ++-- rustfmt.toml | 5 +++++ src/archive/zip.rs | 10 +++------- src/list.rs | 11 ++++++----- src/opts.rs | 4 ++-- src/utils.rs | 3 +-- tests/compress_and_decompress.rs | 3 +-- tests/utils.rs | 1 - 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/build.rs b/build.rs index 5372154..1c1a0e9 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,8 @@ +use std::{env, fs::create_dir_all, path::Path}; + use clap::{ArgEnum, IntoApp}; use clap_generate::{generate_to, Shell}; -use std::{env, fs::create_dir_all, path::Path}; - include!("src/opts.rs"); fn main() { diff --git a/rustfmt.toml b/rustfmt.toml index 2ac63bb..a3badd9 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,4 @@ +# Stable features max_width = 120 use_field_init_shorthand = true newline_style = "Unix" @@ -6,5 +7,9 @@ reorder_imports = true reorder_modules = true use_try_shorthand = true use_small_heuristics = "Max" + +# Unstable features (nightly only) unstable_features = true force_multiline_blocks = true +group_imports = "StdExternalCrate" +imports_granularity = "Crate" diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 50ec853..46aa497 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -7,10 +7,10 @@ use std::{ }; use fs_err as fs; - use walkdir::WalkDir; use zip::{self, read::ZipFile, ZipArchive}; +use self::utf8::get_invalid_utf8_paths; use crate::{ info, list::FileInArchive, @@ -18,8 +18,6 @@ use crate::{ QuestionPolicy, }; -use self::utf8::get_invalid_utf8_paths; - /// Unpacks the archive given by `archive` into the folder given by `into`. pub fn unpack_archive( mut archive: ZipArchive, @@ -158,8 +156,7 @@ fn check_for_comments(file: &ZipFile) { #[cfg(unix)] fn __unix_set_permissions(file_path: &Path, file: &ZipFile) -> crate::Result<()> { - use std::fs::Permissions; - use std::os::unix::fs::PermissionsExt; + use std::{fs::Permissions, os::unix::fs::PermissionsExt}; if let Some(mode) = file.unix_mode() { fs::set_permissions(file_path, Permissions::from_mode(mode))?; @@ -175,8 +172,7 @@ mod utf8 { // Sad double reference in order to make `filter` happy in `get_invalid_utf8_paths` #[cfg(unix)] fn is_invalid_utf8(path: &&Path) -> bool { - use std::os::unix::prelude::OsStrExt; - use std::str; + use std::{os::unix::prelude::OsStrExt, str}; // str::from_utf8 does not make any allocations let bytes = path.as_os_str().as_bytes(); diff --git a/src/list.rs b/src/list.rs index 23af652..fceb05e 100644 --- a/src/list.rs +++ b/src/list.rs @@ -1,8 +1,9 @@ //! Implementation of the 'list' command, print list of files in an archive -use self::tree::Tree; use std::path::{Path, PathBuf}; +use self::tree::Tree; + /// Options controlling how archive contents should be listed #[derive(Debug, Clone, Copy)] pub struct ListOptions { @@ -56,11 +57,11 @@ fn print_entry(name: impl std::fmt::Display, is_dir: bool) { /// we have to construct the tree structure ourselves to be able to /// display them as a tree mod tree { - use super::FileInArchive; + use std::{ffi::OsString, iter::FromIterator, path}; + use linked_hash_map::LinkedHashMap; - use std::ffi::OsString; - use std::iter::FromIterator; - use std::path; + + use super::FileInArchive; /// Directory tree #[derive(Debug, Default)] diff --git a/src/opts.rs b/src/opts.rs index 553d033..f8891e7 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -1,7 +1,7 @@ -use clap::{Parser, ValueHint}; - use std::path::PathBuf; +use clap::{Parser, ValueHint}; + /// Command line options #[derive(Parser, Debug)] #[clap(version, about)] diff --git a/src/utils.rs b/src/utils.rs index 17b47fb..79bdf8c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,8 +4,7 @@ use std::{ cmp, env, ffi::OsStr, io, - path::Component, - path::{Path, PathBuf}, + path::{Component, Path, PathBuf}, }; use fs_err as fs; diff --git a/tests/compress_and_decompress.rs b/tests/compress_and_decompress.rs index 3f06690..9405ae0 100644 --- a/tests/compress_and_decompress.rs +++ b/tests/compress_and_decompress.rs @@ -7,9 +7,8 @@ use std::{ time::Duration, }; -use ouch::{commands::run, Opts, QuestionPolicy, Subcommand}; - use fs_err as fs; +use ouch::{commands::run, Opts, QuestionPolicy, Subcommand}; use rand::{rngs::SmallRng, RngCore, SeedableRng}; use tempfile::NamedTempFile; use utils::*; diff --git a/tests/utils.rs b/tests/utils.rs index 538c802..ec3ae7a 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -5,7 +5,6 @@ use std::path::{Path, PathBuf}; use fs_err as fs; - use ouch::{commands::run, Opts, QuestionPolicy, Subcommand}; pub fn create_empty_dir(at: &Path, filename: &str) -> PathBuf {