From 9ca8feeb14aa4eaa7a5e3a70a95b9d9841820a5b Mon Sep 17 00:00:00 2001 From: LeopoldArkham Date: Sun, 15 Dec 2019 19:39:36 +0100 Subject: [PATCH] cargo fmt --- src/file_size_opts/defaults.rs | 11 ++------ src/file_size_opts/mod.rs | 6 ----- src/lib.rs | 6 +---- src/scales.rs | 30 +++------------------- tests/test.rs | 47 +++++++++------------------------- 5 files changed, 19 insertions(+), 81 deletions(-) diff --git a/src/file_size_opts/defaults.rs b/src/file_size_opts/defaults.rs index 9d212ed..8860c44 100644 --- a/src/file_size_opts/defaults.rs +++ b/src/file_size_opts/defaults.rs @@ -1,9 +1,4 @@ -use crate::file_size_opts::{ - FileSizeOpts, - Kilo, - FixedAt, -}; - +use crate::file_size_opts::{FileSizeOpts, FixedAt, Kilo}; /// Options to display sizes in the binary format. pub const BINARY: FileSizeOpts = FileSizeOpts { @@ -18,7 +13,6 @@ pub const BINARY: FileSizeOpts = FileSizeOpts { allow_negative: false, }; - /// Options to display sizes in the decimal format. pub const DECIMAL: FileSizeOpts = FileSizeOpts { divider: Kilo::Decimal, @@ -32,7 +26,6 @@ pub const DECIMAL: FileSizeOpts = FileSizeOpts { allow_negative: false, }; - /// Options to display sizes in the "conventional" format. /// This 1024 as the value of the `Kilo`, but displays decimal-style units (`KB`, not `KiB`). pub const CONVENTIONAL: FileSizeOpts = FileSizeOpts { @@ -45,4 +38,4 @@ pub const CONVENTIONAL: FileSizeOpts = FileSizeOpts { space: true, suffix: "", allow_negative: false, -}; \ No newline at end of file +}; diff --git a/src/file_size_opts/mod.rs b/src/file_size_opts/mod.rs index c023e1d..0901678 100644 --- a/src/file_size_opts/mod.rs +++ b/src/file_size_opts/mod.rs @@ -1,4 +1,3 @@ - //! Describes the struct that holds the options needed by the `file_size` method. //! The three most common formats are provided as constants to be used easily @@ -6,8 +5,6 @@ pub mod defaults; pub use self::defaults::*; - - #[derive(Debug, PartialEq, Copy, Clone)] /// Holds the standard to use when displying the size. pub enum Kilo { @@ -17,7 +14,6 @@ pub enum Kilo { Binary, } - #[derive(Debug, Copy, Clone)] /// Forces a certain representation of the resulting file size. pub enum FixedAt { @@ -33,7 +29,6 @@ pub enum FixedAt { No, } - /// Holds the options for the `file_size` method. #[derive(Debug)] pub struct FileSizeOpts { @@ -65,7 +60,6 @@ pub struct FileSizeOpts { pub allow_negative: bool, } - impl AsRef for FileSizeOpts { fn as_ref(&self) -> &FileSizeOpts { self diff --git a/src/lib.rs b/src/lib.rs index 841fe47..a5c5a1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,9 +30,8 @@ //! If you wish to customize the way sizes are displayed, you may create your own custom `FileSizeOpts` struct //! and pass that to the method. See the `custom_options.rs` file in the example folder. -mod scales; pub mod file_size_opts; - +mod scales; /// The trait for the `file_size` method pub trait FileSize { @@ -61,7 +60,6 @@ fn f64_eq(left: f64, right: f64) -> bool { use self::file_size_opts::*; - macro_rules! impl_file_size_u { (for $($t:ty)*) => ($( impl FileSize for $t { @@ -114,7 +112,6 @@ macro_rules! impl_file_size_u { )*) } - macro_rules! impl_file_size_i { (for $($t:ty)*) => ($( impl FileSize for $t { @@ -137,6 +134,5 @@ macro_rules! impl_file_size_i { )*) } - impl_file_size_u!(for usize u8 u16 u32 u64); impl_file_size_i!(for isize i8 i16 i32 i64); diff --git a/src/scales.rs b/src/scales.rs index ecd6564..bc45c65 100644 --- a/src/scales.rs +++ b/src/scales.rs @@ -1,15 +1,4 @@ -pub(crate) static SCALE_DECIMAL: [&str; 9] = [ - "B", - "KB", - "MB", - "GB", - "TB", - "PB", - "EB", - "ZB", - "YB", -]; - +pub(crate) static SCALE_DECIMAL: [&str; 9] = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; pub(crate) static SCALE_DECIMAL_LONG: [&str; 9] = [ "Bytes", @@ -23,19 +12,8 @@ pub(crate) static SCALE_DECIMAL_LONG: [&str; 9] = [ "Yottabytes", ]; - -pub(crate) static SCALE_BINARY: [&str; 9] = [ - "B", - "KiB", - "MiB", - "GiB", - "TiB", - "PiB", - "EiB", - "ZiB", - "YiB", -]; - +pub(crate) static SCALE_BINARY: [&str; 9] = + ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]; pub(crate) static SCALE_BINARY_LONG: [&str; 9] = [ "Bytes", @@ -47,4 +25,4 @@ pub(crate) static SCALE_BINARY_LONG: [&str; 9] = [ "Exbibytes", "Zebibytes", "Yobibytes", -]; \ No newline at end of file +]; diff --git a/tests/test.rs b/tests/test.rs index dc1329d..020988f 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,8 +1,10 @@ -use humansize::{file_size_opts::{self, BINARY, DECIMAL, CONVENTIONAL}, FileSize}; +use humansize::{ + file_size_opts::{self, BINARY, CONVENTIONAL, DECIMAL}, + FileSize, +}; #[test] fn test_sizes() { - assert_eq!(0.file_size(BINARY).unwrap(), "0 B"); assert_eq!(999.file_size(BINARY).unwrap(), "999 B"); assert_eq!(1000.file_size(BINARY).unwrap(), "1000 B"); @@ -67,7 +69,6 @@ fn test_sizes() { assert_eq!((5500).file_size(&semi_custom_options7).unwrap(), "5.50 KB"); } - #[test] fn use_custom_option_struct_twice() { let options = file_size_opts::FileSizeOpts { @@ -75,18 +76,11 @@ fn use_custom_option_struct_twice() { ..file_size_opts::DECIMAL }; - assert_eq!( - 1500.file_size(&options).unwrap(), - "1.50 Kilobyte", - ); + assert_eq!(1500.file_size(&options).unwrap(), "1.50 Kilobyte",); - assert_eq!( - 2500.file_size(&options).unwrap(), - "2.50 Kilobytes", - ); + assert_eq!(2500.file_size(&options).unwrap(), "2.50 Kilobytes",); } - #[test] fn pluralization_works() { let options = file_size_opts::FileSizeOpts { @@ -95,25 +89,13 @@ fn pluralization_works() { ..file_size_opts::DECIMAL }; - assert_eq!( - 1.file_size(&options).unwrap(), - "1.00 Byte", - ); + assert_eq!(1.file_size(&options).unwrap(), "1.00 Byte",); - assert_eq!( - 1000.file_size(&options).unwrap(), - "1.00 Kilobyte", - ); + assert_eq!(1000.file_size(&options).unwrap(), "1.00 Kilobyte",); - assert_eq!( - 1000000.file_size(&options).unwrap(), - "1.00 Megabyte", - ); + assert_eq!(1000000.file_size(&options).unwrap(), "1.00 Megabyte",); - assert_eq!( - 1000000000.file_size(&options).unwrap(), - "1.00 Gigabyte", - ); + assert_eq!(1000000000.file_size(&options).unwrap(), "1.00 Gigabyte",); assert_eq!( 1000000000000_i64.file_size(&options).unwrap(), @@ -131,7 +113,6 @@ fn pluralization_works() { ); } - #[test] fn max_value_decimal() { let options = file_size_opts::FileSizeOpts { @@ -146,7 +127,6 @@ fn max_value_decimal() { ); } - #[test] fn max_value_binary() { let options = file_size_opts::FileSizeOpts { @@ -155,8 +135,5 @@ fn max_value_binary() { ..file_size_opts::BINARY }; - assert_eq!( - (std::u64::MAX).file_size(&options).unwrap(), - "16 Exbibytes", - ); -} \ No newline at end of file + assert_eq!((std::u64::MAX).file_size(&options).unwrap(), "16 Exbibytes",); +}