From 3bab18976a817f25c263cc85b7313853be7c524c Mon Sep 17 00:00:00 2001 From: Nikola Hristov Date: Sun, 6 Oct 2024 10:38:56 +0300 Subject: [PATCH] --- Source/Fn/Binary/Command.rs | 3 +- Source/Fn/Binary/Command/Entry.rs | 14 ++------ Source/Fn/Binary/Command/Parallel.rs | 6 +--- Source/Fn/Binary/Command/Sequential.rs | 22 ++++-------- Source/Fn/Summary.rs | 46 ++++++-------------------- Source/Fn/Summary/Difference.rs | 12 +++---- Source/Fn/Summary/First.rs | 3 +- Source/Fn/Summary/Group.rs | 14 ++++---- Source/Fn/Summary/Insert.rs | 6 +--- Source/Struct/Binary/Command.rs | 9 ++--- Source/Struct/Binary/Command/Option.rs | 15 ++------- Source/Struct/Summary/Difference.rs | 3 +- build.rs | 6 ++-- 13 files changed, 44 insertions(+), 115 deletions(-) diff --git a/Source/Fn/Binary/Command.rs b/Source/Fn/Binary/Command.rs index bedd4c2..dfb539d 100644 --- a/Source/Fn/Binary/Command.rs +++ b/Source/Fn/Binary/Command.rs @@ -31,8 +31,7 @@ /// ```rust /// let matches = Fn(); /// let exclude = matches.value_of("Exclude").unwrap_or("node_modules"); -/// let omit = -/// matches.values_of("Omit").unwrap_or_default().collect::>(); +/// let omit = matches.values_of("Omit").unwrap_or_default().collect::>(); /// let parallel = matches.is_present("Parallel"); /// let pattern = matches.value_of("Pattern").unwrap_or(".git"); /// let root = matches.value_of("Root").unwrap_or("."); diff --git a/Source/Fn/Binary/Command/Entry.rs b/Source/Fn/Binary/Command/Entry.rs index 6c35391..6788d55 100644 --- a/Source/Fn/Binary/Command/Entry.rs +++ b/Source/Fn/Binary/Command/Entry.rs @@ -40,8 +40,7 @@ pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }:&Option) -> Return { .follow_links(false) .into_iter() .filter_map(|Entry| { - let Path = - Entry.expect("Cannot Entry.").path().display().to_string(); + let Path = Entry.expect("Cannot Entry.").path().display().to_string(); // TODO: Separate this into Entry/Exclude.rs if !Exclude @@ -50,11 +49,7 @@ pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }:&Option) -> Return { .filter(|Exclude| *Pattern != *Exclude) .any(|Exclude| Path.contains(&Exclude)) { - Some( - Path.split(*Separator) - .map(|Entry| Entry.to_string()) - .collect(), - ) + Some(Path.split(*Separator).map(|Entry| Entry.to_string()).collect()) } else { None } @@ -64,7 +59,4 @@ pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }:&Option) -> Return { use walkdir::WalkDir; -use crate::Struct::Binary::Command::{ - Entry::Type as Return, - Option::Struct as Option, -}; +use crate::Struct::Binary::Command::{Entry::Type as Return, Option::Struct as Option}; diff --git a/Source/Fn/Binary/Command/Parallel.rs b/Source/Fn/Binary/Command/Parallel.rs index da3a971..84af571 100644 --- a/Source/Fn/Binary/Command/Parallel.rs +++ b/Source/Fn/Binary/Command/Parallel.rs @@ -21,11 +21,7 @@ /// /// ```rust /// let options = Option { -/// Entry:vec![vec![ -/// "path".to_string(), -/// "to".to_string(), -/// "file.git".to_string(), -/// ]], +/// Entry:vec![vec!["path".to_string(), "to".to_string(), "file.git".to_string()]], /// Separator:'/', /// Pattern:".git".to_string(), /// Omit:vec!["target".to_string()], diff --git a/Source/Fn/Binary/Command/Sequential.rs b/Source/Fn/Binary/Command/Sequential.rs index 38a14f8..9f8965e 100644 --- a/Source/Fn/Binary/Command/Sequential.rs +++ b/Source/Fn/Binary/Command/Sequential.rs @@ -21,11 +21,7 @@ /// /// ```rust /// let options = Option { -/// Entry:vec![vec![ -/// "path".to_string(), -/// "to".to_string(), -/// "file.git".to_string(), -/// ]], +/// Entry:vec![vec!["path".to_string(), "to".to_string(), "file.git".to_string()]], /// Separator:'/', /// Pattern:".git".to_string(), /// Omit:vec!["target".to_string()], @@ -42,9 +38,10 @@ pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }:Option) { Entry .into_iter() .filter_map(|Entry| { - Entry.last().filter(|Last| *Last == &Pattern).map(|_| { - Entry[0..Entry.len() - 1].join(&Separator.to_string()) - }) + Entry + .last() + .filter(|Last| *Last == &Pattern) + .map(|_| Entry[0..Entry.len() - 1].join(&Separator.to_string())) }) .map(|Entry| { let Omit = Omit.clone(); @@ -58,10 +55,7 @@ pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }:Option) { { Ok(Summary) => Ok((Entry, Summary)), Err(_Error) => { - Err(format!( - "Error generating summary for {}: {}", - Entry, _Error - )) + Err(format!("Error generating summary for {}: {}", Entry, _Error)) }, } } @@ -69,9 +63,7 @@ pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }:Option) { ) .await; - crate::Fn::Summary::Group::Fn( - Queue.into_iter().filter_map(Result::ok).collect::>(), - ); + crate::Fn::Summary::Group::Fn(Queue.into_iter().filter_map(Result::ok).collect::>()); } use crate::Struct::Binary::Command::Entry::Struct as Option; diff --git a/Source/Fn/Summary.rs b/Source/Fn/Summary.rs index 5b1a0f1..5d50b3c 100644 --- a/Source/Fn/Summary.rs +++ b/Source/Fn/Summary.rs @@ -28,11 +28,9 @@ /// # Example /// /// ```rust -/// let options = crate::Struct::Summary::Difference::Struct { -/// Omit:vec!["(?i)\\.log$".to_string()], -/// }; -/// let summary = -/// Fn("/path/to/repo", &options).await.expect("Cannot generate summary."); +/// let options = +/// crate::Struct::Summary::Difference::Struct { Omit:vec!["(?i)\\.log$".to_string()] }; +/// let summary = Fn("/path/to/repo", &options).await.expect("Cannot generate summary."); /// for entry in summary.iter() { /// println!("{:?}", entry); /// } @@ -62,12 +60,9 @@ pub async fn Fn( .map(|Commit| { ( Tag.to_string(), - DateTime::from_timestamp( - Commit.time().seconds(), - 0, - ) - .unwrap() - .fixed_offset(), + DateTime::from_timestamp(Commit.time().seconds(), 0) + .unwrap() + .fixed_offset(), ) }) }) @@ -76,39 +71,25 @@ pub async fn Fn( Date.sort_by(|A, B| A.1.cmp(&B.1)); - let Tag:Vec = - Date.into_iter().map(|(Tag, _)| Tag).collect(); + let Tag:Vec = Date.into_iter().map(|(Tag, _)| Tag).collect(); let Head = Repository.head()?; - let First = Repository - .find_commit(First::Fn(&Repository)?)? - .id() - .to_string(); + let First = Repository.find_commit(First::Fn(&Repository)?)?.id().to_string(); let Last = Head.peel_to_commit()?.id().to_string(); if Tag.is_empty() { Insert::Fn( &Summary, - crate::Fn::Summary::Difference::Fn( - &Repository, - &First, - &Last, - Option, - )?, + crate::Fn::Summary::Difference::Fn(&Repository, &First, &Last, Option)?, format!("🗣️ Summary from first commit to last commit"), ) } else { if let Some(Latest) = Tag.last() { Insert::Fn( &Summary, - crate::Fn::Summary::Difference::Fn( - &Repository, - Latest, - &Last, - Option, - )?, + crate::Fn::Summary::Difference::Fn(&Repository, Latest, &Last, Option)?, format!("🗣️ Summary from {} to last commit", Latest), ); } @@ -119,12 +100,7 @@ pub async fn Fn( Insert::Fn( &Summary, - crate::Fn::Summary::Difference::Fn( - &Repository, - &Start, - &End, - Option, - )?, + crate::Fn::Summary::Difference::Fn(&Repository, &Start, &End, Option)?, format!("🗣️ Summary from {} to {}", Start, End), ); } diff --git a/Source/Fn/Summary/Difference.rs b/Source/Fn/Summary/Difference.rs index 35b0e5a..2edff77 100644 --- a/Source/Fn/Summary/Difference.rs +++ b/Source/Fn/Summary/Difference.rs @@ -26,15 +26,13 @@ /// # Example /// /// ```rust -/// let repo = git2::Repository::open("/path/to/repo") -/// .expect("Cannot open repository."); +/// let repo = git2::Repository::open("/path/to/repo").expect("Cannot open repository."); /// let start_commit = "abc123"; /// let end_commit = "def456"; -/// let options = crate::Struct::Summary::Difference::Struct { -/// Omit:vec!["(?i)\\.log$".to_string()], -/// }; -/// let diff_summary = Fn(&repo, start_commit, end_commit, &options) -/// .expect("Cannot generate diff."); +/// let options = +/// crate::Struct::Summary::Difference::Struct { Omit:vec!["(?i)\\.log$".to_string()] }; +/// let diff_summary = +/// Fn(&repo, start_commit, end_commit, &options).expect("Cannot generate diff."); /// println!("{}", diff_summary); /// ``` /// diff --git a/Source/Fn/Summary/First.rs b/Source/Fn/Summary/First.rs index 81d63c1..1253dd3 100644 --- a/Source/Fn/Summary/First.rs +++ b/Source/Fn/Summary/First.rs @@ -23,8 +23,7 @@ /// # Example /// /// ```rust -/// let repo = git2::Repository::open("/path/to/repo") -/// .expect("Cannot open repository."); +/// let repo = git2::Repository::open("/path/to/repo").expect("Cannot open repository."); /// let first_commit_oid = Fn(&repo).expect("Cannot retrieve first commit."); /// println!("First commit OID: {}", first_commit_oid); /// ``` diff --git a/Source/Fn/Summary/Group.rs b/Source/Fn/Summary/Group.rs index 2ce2181..ffbb0f1 100644 --- a/Source/Fn/Summary/Group.rs +++ b/Source/Fn/Summary/Group.rs @@ -33,10 +33,7 @@ /// let mut summary2 = DashMap::new(); /// summary2.insert(2, ("diff2".to_string(), "message2".to_string())); /// -/// let summaries = vec![ -/// ("entry1".to_string(), summary1), -/// ("entry2".to_string(), summary2), -/// ]; +/// let summaries = vec![("entry1".to_string(), summary1), ("entry2".to_string(), summary2)]; /// /// Fn(summaries); /// ``` @@ -68,16 +65,17 @@ where } } - Output.into_iter().sorted_by(|(A, _), (B, _)| A.cmp(B)).for_each( - |(Message, Difference)| { + Output + .into_iter() + .sorted_by(|(A, _), (B, _)| A.cmp(B)) + .for_each(|(Message, Difference)| { println!("{}", Message); Difference .into_iter() .sorted_by_key(|Difference| Reverse(Difference.len())) .for_each(|Difference| println!("{}", Difference)); - }, - ); + }); } use std::{cmp::Reverse, collections::HashSet}; diff --git a/Source/Fn/Summary/Insert.rs b/Source/Fn/Summary/Insert.rs index 8e17a46..6997ea1 100644 --- a/Source/Fn/Summary/Insert.rs +++ b/Source/Fn/Summary/Insert.rs @@ -29,11 +29,7 @@ /// # Errors /// /// This function does not return errors. -pub fn Fn( - Summary:&DashMap, - Difference:String, - Message:String, -) { +pub fn Fn(Summary:&DashMap, Difference:String, Message:String) { Summary.insert(Hash::Fn(&Difference), (Difference, Message)); } diff --git a/Source/Struct/Binary/Command.rs b/Source/Struct/Binary/Command.rs index ebce6ca..16a08e4 100644 --- a/Source/Struct/Binary/Command.rs +++ b/Source/Struct/Binary/Command.rs @@ -8,11 +8,7 @@ pub struct Struct { pub Separator:Option::Separator, /// A boxed asynchronous function that returns a pinned future. - pub Fn: Box< - dyn Fn() -> Pin + Send + 'static>> - + Send - + 'static, - >, + pub Fn:Box Pin + Send + 'static>> + Send + 'static>, } impl Struct { @@ -32,8 +28,7 @@ impl Struct { Separator:std::path::MAIN_SEPARATOR, Fn:Box::new(|| { Box::pin(async move { - let Option = - Entry::Struct::Fn(&Option::Struct::Fn(Struct::Fn())); + let Option = Entry::Struct::Fn(&Option::Struct::Fn(Struct::Fn())); match Option.Parallel { true => { diff --git a/Source/Struct/Binary/Command/Option.rs b/Source/Struct/Binary/Command/Option.rs index 0ddfc52..12c1b18 100644 --- a/Source/Struct/Binary/Command/Option.rs +++ b/Source/Struct/Binary/Command/Option.rs @@ -47,14 +47,8 @@ impl Struct { .map(|Exclude| Exclude.to_string()) .collect::>(), Parallel:Command().get_flag("Parallel"), - Pattern:Command() - .get_one::("Pattern") - .expect("Cannot Pattern.") - .to_owned(), - Root:Command() - .get_one::("Root") - .expect("Cannot Root.") - .to_owned(), + Pattern:Command().get_one::("Pattern").expect("Cannot Pattern.").to_owned(), + Root:Command().get_one::("Root").expect("Cannot Root.").to_owned(), Separator, Omit:Command() .get_many::("Omit") @@ -65,10 +59,7 @@ impl Struct { } } -use crate::{ - Fn::Binary::Command::Fn as Command, - Struct::Binary::Command::Struct as Option, -}; +use crate::{Fn::Binary::Command::Fn as Command, Struct::Binary::Command::Struct as Option}; /// Type alias for a vector of strings representing command options. pub type Command = Vec; diff --git a/Source/Struct/Summary/Difference.rs b/Source/Struct/Summary/Difference.rs index b2e220b..358c49a 100644 --- a/Source/Struct/Summary/Difference.rs +++ b/Source/Struct/Summary/Difference.rs @@ -9,8 +9,7 @@ /// # Example /// /// ```rust -/// let omit_patterns = -/// Struct { Omit:vec!["pattern1".to_string(), "pattern2".to_string()] }; +/// let omit_patterns = Struct { Omit:vec!["pattern1".to_string(), "pattern2".to_string()] }; /// ``` pub struct Struct { /// A vector of strings representing patterns to omit. diff --git a/build.rs b/build.rs index 80f6a43..a107a81 100644 --- a/build.rs +++ b/build.rs @@ -15,10 +15,8 @@ fn main() { println!( "cargo:rustc-env=CARGO_PKG_VERSION={}", - (toml::from_str::( - &fs::read_to_string("Cargo.toml").expect("Cannot Cargo.toml.") - ) - .expect("Cannot toml.")) + (toml::from_str::(&fs::read_to_string("Cargo.toml").expect("Cannot Cargo.toml.")) + .expect("Cannot toml.")) .package .version );