diff --git a/rustfmt.toml b/rustfmt.toml index 5c206f3..22035a9 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,7 +1,8 @@ +edition = "2021" max_width = 100 -array_width = 92 +use_small_heuristics = "Max" tab_spaces = 4 -newline_style = "unix" # f*** windows style +newline_style = "Unix" reorder_imports = true use_field_init_shorthand = true use_try_shorthand = true @@ -9,14 +10,20 @@ match_block_trailing_comma = true # they seem to be stable in nearest future, but for now we use it only for nightly CI check unstable_features = true +version = "Two" condense_wildcard_suffixes = true comment_width = 100 +doc_comment_code_block_width = 100 format_code_in_doc_comments = true format_macro_bodies = true format_macro_matchers = true format_strings = true fn_single_line = true +overflow_delimited_expr = true +reorder_impl_items = true imports_granularity = "One" +inline_attribute_width = 100 match_arm_blocks = false normalize_comments = true +where_single_line = true wrap_comments = true diff --git a/src/algorithm/extra.rs b/src/algorithm/extra.rs index dc8ce07..baee70b 100644 --- a/src/algorithm/extra.rs +++ b/src/algorithm/extra.rs @@ -36,10 +36,7 @@ pub fn bin_search(arr: &[T], targ: T) -> Option { /// use ognlib::algorithm::extra::mask_match; /// /// let nums1 = mask_match(100, 200, "1?0"); -/// assert_eq!( -/// nums1, -/// vec![100, 110, 120, 130, 140, 150, 160, 170, 180, 190] -/// ); +/// assert_eq!(nums1, vec![100, 110, 120, 130, 140, 150, 160, 170, 180, 190]); /// /// let nums2 = mask_match(1, 10, "*"); /// assert_eq!(nums2, vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); @@ -51,18 +48,13 @@ pub fn bin_search(arr: &[T], targ: T) -> Option { /// ``` /// use {ognlib::algorithm::extra::mask_match, rayon::prelude::*}; /// -/// let nums_div_by_169: Vec = mask_match(1, 1000000000, "123*567?") -/// .into_par_iter() -/// .filter(|&x| x % 169 == 0) -/// .collect(); +/// let nums_div_by_169: Vec = +/// mask_match(1, 1000000000, "123*567?").into_par_iter().filter(|&x| x % 169 == 0).collect(); /// -/// assert_eq!( -/// nums_div_by_169, -/// vec![ -/// 12325677, 12385672, 123157567, 123165679, 123225674, 123326567, 123495567, 123515678, -/// 123575673, 123664567, 123833567, 123865677, 123925672, -/// ] -/// ) +/// assert_eq!(nums_div_by_169, vec![ +/// 12325677, 12385672, 123157567, 123165679, 123225674, 123326567, 123495567, 123515678, +/// 123575673, 123664567, 123833567, 123865677, 123925672, +/// ]) /// ``` pub fn mask_match(lower: usize, upper: usize, mask: &str) -> Vec { @@ -73,8 +65,5 @@ pub fn mask_match(lower: usize, upper: usize, mask: &str) -> Vec { let mask = mask.replace('*', ".*"); let mask = mask.replace('?', ".?"); let re = Regex::new(&("^".to_owned() + &mask + "$")).unwrap(); - (lower..=upper) - .into_par_iter() - .filter(|num| re.is_match(&num.to_string())) - .collect() + (lower..=upper).into_par_iter().filter(|num| re.is_match(&num.to_string())).collect() } diff --git a/src/algorithm/prime.rs b/src/algorithm/prime.rs index c325eb9..76d58e5 100644 --- a/src/algorithm/prime.rs +++ b/src/algorithm/prime.rs @@ -120,10 +120,7 @@ impl Prime for isize { /// ``` /// use ognlib::algorithm::prime::{sqrtest, PrimeStatus, PrimeStatusError}; /// -/// assert_eq!( -/// sqrtest(1).unwrap_err().to_string(), -/// "This number is neither prime nor composite", -/// ); +/// assert_eq!(sqrtest(1).unwrap_err().to_string(), "This number is neither prime nor composite",); /// assert_eq!(sqrtest(13).ok(), Some(PrimeStatus::Prime)); /// assert_eq!(sqrtest(455).ok(), Some(PrimeStatus::Composite)); /// ``` @@ -174,11 +171,7 @@ pub fn wilson_th(n: isize) -> Result { fact = (fact * i) % n; } - if fact + 1 == BigInt::from(n) { - Ok(PrimeStatus::Prime) - } else { - Ok(PrimeStatus::Composite) - } + if fact + 1 == BigInt::from(n) { Ok(PrimeStatus::Prime) } else { Ok(PrimeStatus::Composite) } } /// Miller-Rabin's prime test. From diff --git a/src/algorithm/sort.rs b/src/algorithm/sort.rs index b39954f..8218ba3 100644 --- a/src/algorithm/sort.rs +++ b/src/algorithm/sort.rs @@ -90,9 +90,7 @@ pub fn insertion(arr: &mut [T]) { /// ``` pub fn merge(slice: &mut [T]) -where - T: Ord + Clone + Copy + Send + Sync, -{ +where T: Ord + Clone + Copy + Send + Sync { let len = slice.len(); if len < 2 { return; @@ -188,9 +186,7 @@ pub fn cocktail_shaker(arr: &mut [T]) { /// ``` pub fn quick(arr: &mut [T]) -where - T: Ord + Send + Clone, -{ +where T: Ord + Send + Clone { if arr.len() <= 1 { return; } @@ -201,9 +197,7 @@ where } fn partition(arr: &mut [T]) -> usize -where - T: Ord + Send + Clone, -{ +where T: Ord + Send + Clone { let len = arr.len(); let pivot_index = len / 2; let pivot = arr[pivot_index].clone(); diff --git a/src/num/methods.rs b/src/num/methods.rs index 334f462..24bde5c 100644 --- a/src/num/methods.rs +++ b/src/num/methods.rs @@ -1,8 +1,7 @@ //! Functions for operations with number digits. It has already been tested, that Iterators are less //! quick, than `while` loops in these cases. -#[cfg(feature = "num-bigint")] -use {num_bigint::BigInt, rayon::prelude::*}; +#[cfg(feature = "num-bigint")] use {num_bigint::BigInt, rayon::prelude::*}; pub trait Num { /// Represent number as bool like in C. diff --git a/src/num/power.rs b/src/num/power.rs index f6e52f0..7b611b2 100644 --- a/src/num/power.rs +++ b/src/num/power.rs @@ -14,9 +14,7 @@ use std::ops::{Mul, MulAssign, Rem, RemAssign}; /// ``` pub fn bin_pow(mut b: N, mut e: u8) -> N -where - N: MulAssign + From + Copy, -{ +where N: MulAssign + From + Copy { let mut v = N::from(1); while e != 0 { if (e & 1) != 0 { @@ -42,9 +40,7 @@ where /// ``` pub fn modpow(mut b: N, mut e: usize, m: N) -> N -where - N: Mul + Rem + RemAssign + From + Copy + Eq, -{ +where N: Mul + Rem + RemAssign + From + Copy + Eq { let mut result = N::from(1); b %= m; while e != 0 { diff --git a/src/num/radix.rs b/src/num/radix.rs index dd5db7d..99c847b 100644 --- a/src/num/radix.rs +++ b/src/num/radix.rs @@ -87,10 +87,7 @@ impl FromStr for Radix { /// ``` fn from_str(number: &str) -> Result { - Ok(Self { - number: number.parse()?, - base: 10, - }) + Ok(Self { number: number.parse()?, base: 10 }) } } @@ -125,10 +122,7 @@ impl FromStr for StringRadix { /// ``` fn from_str(number: &str) -> Result { - Ok(Self { - number: number.parse::()?.to_string(), - base: 10, - }) + Ok(Self { number: number.parse::()?.to_string(), base: 10 }) } } @@ -892,10 +886,7 @@ impl Radix { /// assert_eq!(n.base(), 2); /// /// let e = Radix::from_radix(444, 3).unwrap_err(); - /// assert_eq!( - /// e.to_string(), - /// "Number contains a digit (4) that is more or equal than base (3)", - /// ); + /// assert_eq!(e.to_string(), "Number contains a digit (4) that is more or equal than base (3)",); /// ``` pub fn from_radix(number: usize, base: u8) -> Result { @@ -1160,10 +1151,7 @@ impl StringRadix { pub fn new(base: u8) -> Result { match base { 0 | 1 | 37.. => Err(RadixError::BaseError(36, base)), - _ => Ok(Self { - number: "0".to_owned(), - base, - }), + _ => Ok(Self { number: "0".to_owned(), base }), } } @@ -1186,10 +1174,7 @@ impl StringRadix { /// assert_eq!(n.base(), 2); /// /// let e = StringRadix::from_radix("129", 9).unwrap_err(); - /// assert_eq!( - /// e.to_string(), - /// "Number contains a digit (9) that is more or equal than base (9)", - /// ); + /// assert_eq!(e.to_string(), "Number contains a digit (9) that is more or equal than base (9)",); /// ``` pub fn from_radix(number: &str, base: u8) -> Result { @@ -1205,10 +1190,7 @@ impl StringRadix { }) { err } else { - Ok(Self { - number: number.to_owned(), - base, - }) + Ok(Self { number: number.to_owned(), base }) } }, } @@ -1287,10 +1269,7 @@ impl StringRadix { 10 => Ok(Self::from(self.to_dec().number)), _ => if self.base == 10 { - Ok(Self::from_dec( - &mut Radix::from(self.number.parse::()?), - k, - )?) + Ok(Self::from_dec(&mut Radix::from(self.number.parse::()?), k)?) } else { Ok(Self::from_dec(&mut self.to_dec(), k)?) }, @@ -1340,10 +1319,7 @@ impl StringRadix { 10 => Ok(self.to_dec()), _ => if self.base == 10 { - Ok(Self::from_dec_to_int( - &mut Radix::from(self.number.parse::()?), - k, - )?) + Ok(Self::from_dec_to_int(&mut Radix::from(self.number.parse::()?), k)?) } else { Ok(Self::from_dec_to_int(&mut self.to_dec(), k)?) },