From d5db810fa9902706ed3e3f86e22a14b0c151ffdd Mon Sep 17 00:00:00 2001 From: Nikola Hristov Date: Sun, 6 Oct 2024 00:05:55 +0300 Subject: [PATCH] --- README.md | 4 +- Source/Fn/Binary/Command.rs | 30 +++++++---- Source/Fn/Binary/Command/Entry.rs | 45 ++++++++++------- Source/Fn/Binary/Command/Parallel.rs | 35 ++++++++----- Source/Fn/Binary/Command/Sequential.rs | 47 ++++++++++------- Source/Fn/Summary.rs | 70 ++++++++++++++++++-------- Source/Fn/Summary/Difference.rs | 34 +++++++------ Source/Fn/Summary/First.rs | 20 +++++--- Source/Fn/Summary/Group.rs | 55 +++++++++++--------- Source/Fn/Summary/Insert.rs | 19 ++++--- Source/Fn/Summary/Insert/Hash.rs | 16 +++--- Source/Library.rs | 15 +++--- Source/Struct/Binary/Command.rs | 35 ++++++++----- Source/Struct/Binary/Command/Entry.rs | 47 ++++++++++------- Source/Struct/Binary/Command/Option.rs | 48 +++++++++++------- Source/Struct/Summary/Difference.rs | 7 ++- build.rs | 13 +++-- 17 files changed, 332 insertions(+), 208 deletions(-) diff --git a/README.md b/README.md index 8c8c3ac..c76e10f 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ processing capabilities, along with flexible file filtering options. Summary -P > Summary.diff ``` -[Summary] will now generate the following [Summary.diff](./Summary.diff) for all the -commits and tags between the first and the last commit. +[Summary] will now generate the following [Summary.diff](./Summary.diff) for all +the commits and tags between the first and the last commit. ## Features diff --git a/Source/Fn/Binary/Command.rs b/Source/Fn/Binary/Command.rs index 4686859..bedd4c2 100644 --- a/Source/Fn/Binary/Command.rs +++ b/Source/Fn/Binary/Command.rs @@ -1,31 +1,38 @@ -/// Creates and returns the command-line argument matches for the `Summary` application. +/// Creates and returns the command-line argument matches for the `Summary` +/// application. /// -/// This function sets up the command-line interface using the `clap` crate, defining various -/// arguments and their properties such as short and long names, help messages, default values, -/// and whether they are required. +/// This function sets up the command-line interface using the `clap` crate, +/// defining various arguments and their properties such as short and long +/// names, help messages, default values, and whether they are required. /// /// # Returns /// -/// Returns an `ArgMatches` instance containing the parsed command-line arguments. +/// Returns an `ArgMatches` instance containing the parsed command-line +/// arguments. /// /// # Arguments /// -/// * `Exclude` - An optional argument to specify patterns to exclude. Default is "node_modules". -/// * `Omit` - An optional argument to specify patterns to omit. Default values are: +/// * `Exclude` - An optional argument to specify patterns to exclude. Default +/// is "node_modules". +/// * `Omit` - An optional argument to specify patterns to omit. Default values +/// are: /// - "(?i)documentation" /// - "(?i)target" /// - "(?i)changelog\.md$" /// - "(?i)summary\.md$" /// * `Parallel` - An optional flag to enable parallel processing. -/// * `Pattern` - An optional argument to specify a pattern to match. Default is ".git". -/// * `Root` - An optional argument to specify the root directory. Default is ".". +/// * `Pattern` - An optional argument to specify a pattern to match. Default is +/// ".git". +/// * `Root` - An optional argument to specify the root directory. Default is +/// ".". /// /// # Example /// /// ```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("."); @@ -33,7 +40,8 @@ /// /// # Errors /// -/// This function will panic if there are issues with the argument definitions or parsing. +/// This function will panic if there are issues with the argument definitions +/// or parsing. pub fn Fn() -> ArgMatches { Command::new("Summary") .version(env!("CARGO_PKG_VERSION")) diff --git a/Source/Fn/Binary/Command/Entry.rs b/Source/Fn/Binary/Command/Entry.rs index 8918e6f..6c35391 100644 --- a/Source/Fn/Binary/Command/Entry.rs +++ b/Source/Fn/Binary/Command/Entry.rs @@ -1,43 +1,47 @@ -/// Generates a list of file paths from the specified root directory, excluding paths that match -/// any of the specified exclude patterns. +/// Generates a list of file paths from the specified root directory, excluding +/// paths that match any of the specified exclude patterns. /// /// # Arguments /// -/// * `Option` - A reference to an `Option` struct containing the following fields: +/// * `Option` - A reference to an `Option` struct containing the following +/// fields: /// - `Exclude`: A vector of strings representing patterns to exclude. -/// - `Pattern`: A string pattern to match against the last element of each entry. +/// - `Pattern`: A string pattern to match against the last element of each +/// entry. /// - `Root`: The root directory to start the walk from. /// - `Separator`: The separator used for splitting file paths. /// /// # Returns /// -/// Returns a vector of vectors, where each inner vector contains the components of a file path -/// split by the specified separator. +/// Returns a vector of vectors, where each inner vector contains the components +/// of a file path split by the specified separator. /// /// # Panics /// -/// This function will panic if it encounters an error while reading a directory entry. +/// This function will panic if it encounters an error while reading a directory +/// entry. /// /// # Example /// /// ``` /// let options = Option { -/// Exclude: vec!["node_modules".to_string(), "target".to_string()], -/// Pattern: ".git".to_string(), -/// Root: ".".to_string(), -/// Separator: '/', +/// Exclude:vec!["node_modules".to_string(), "target".to_string()], +/// Pattern:".git".to_string(), +/// Root:".".to_string(), +/// Separator:'/', /// }; /// let paths = Fn(&options); /// for path in paths { -/// println!("{:?}", path); +/// println!("{:?}", path); /// } /// ``` -pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }: &Option) -> Return { +pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }:&Option) -> Return { WalkDir::new(Root) .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 @@ -46,7 +50,11 @@ 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 } @@ -54,6 +62,9 @@ pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }: &Option) -> Return { .collect::>() } -use crate::Struct::Binary::Command::{Entry::Type as Return, Option::Struct as Option}; - use walkdir::WalkDir; + +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 65b0ca4..da3a971 100644 --- a/Source/Fn/Binary/Command/Parallel.rs +++ b/Source/Fn/Binary/Command/Parallel.rs @@ -1,34 +1,43 @@ -/// Asynchronously processes entries to generate summaries and outputs the results. +/// Asynchronously processes entries to generate summaries and outputs the +/// results. /// /// This function performs the following steps: -/// 1. Filters and processes the provided entries based on the given pattern and separator. +/// 1. Filters and processes the provided entries based on the given pattern and +/// separator. /// 2. Spawns asynchronous tasks to generate summaries for each entry. /// 3. Collects the results and outputs them. /// /// # Arguments /// /// * `Option` - A struct containing the following fields: -/// - `Entry`: A vector of vectors, where each inner vector contains the components of a file path. +/// - `Entry`: A vector of vectors, where each inner vector contains the +/// components of a file path. /// - `Separator`: A character used to join the components of the file path. -/// - `Pattern`: A string pattern to match against the last element of each entry. +/// - `Pattern`: A string pattern to match against the last element of each +/// entry. /// - `Omit`: A vector of strings representing patterns to omit. /// /// # Example /// /// ```rust /// let options = Option { -/// Entry: vec![vec!["path".to_string(), "to".to_string(), "file.git".to_string()]], -/// Separator: '/', -/// Pattern: ".git".to_string(), -/// Omit: vec!["target".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()], /// }; /// Fn(options).await; /// ``` /// /// # Errors /// -/// This function will log errors if it fails to generate summaries or send results. -pub async fn Fn(Option { Entry, Separator, Pattern, Omit, .. }: Option) { +/// This function will log errors if it fails to generate summaries or send +/// results. +pub async fn Fn(Option { Entry, Separator, Pattern, Omit, .. }:Option) { let (Allow, mut Mark) = tokio::sync::mpsc::unbounded_channel(); let Queue = futures::stream::FuturesUnordered::new(); @@ -57,9 +66,11 @@ pub async fn Fn(Option { Entry, Separator, Pattern, Omit, .. }: Option) { if let Err(_Error) = Allow.send((Entry, Summary)) { eprintln!("Cannot Allow: {}", _Error); } - } + }, - Err(_Error) => eprintln!("Cannot Summary for {}: {}", Entry, _Error), + Err(_Error) => { + eprintln!("Cannot Summary for {}: {}", Entry, _Error) + }, } })); } diff --git a/Source/Fn/Binary/Command/Sequential.rs b/Source/Fn/Binary/Command/Sequential.rs index 4986cdb..38a14f8 100644 --- a/Source/Fn/Binary/Command/Sequential.rs +++ b/Source/Fn/Binary/Command/Sequential.rs @@ -1,42 +1,50 @@ -/// Asynchronously processes entries to generate summaries and outputs the results sequentially. +/// Asynchronously processes entries to generate summaries and outputs the +/// results sequentially. /// /// This function performs the following steps: -/// 1. Filters and processes the provided entries based on the given pattern and separator. +/// 1. Filters and processes the provided entries based on the given pattern and +/// separator. /// 2. Spawns asynchronous tasks to generate summaries for each entry. /// 3. Collects the results and outputs them. /// /// # Arguments /// /// * `Option` - A struct containing the following fields: -/// - `Entry`: A vector of vectors, where each inner vector contains the components of a file path. +/// - `Entry`: A vector of vectors, where each inner vector contains the +/// components of a file path. /// - `Separator`: A character used to join the components of the file path. -/// - `Pattern`: A string pattern to match against the last element of each entry. +/// - `Pattern`: A string pattern to match against the last element of each +/// entry. /// - `Omit`: A vector of strings representing patterns to omit. /// /// # Example /// /// ```rust /// let options = Option { -/// Entry: vec![vec!["path".to_string(), "to".to_string(), "file.git".to_string()]], -/// Separator: '/', -/// Pattern: ".git".to_string(), -/// Omit: vec!["target".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()], /// }; /// Fn(options).await; /// ``` /// /// # Errors /// -/// This function will log errors if it fails to generate summaries or send results. -pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }: Option) { +/// This function will log errors if it fails to generate summaries or send +/// results. +pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }:Option) { let Queue = futures::future::join_all( 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(); @@ -50,15 +58,20 @@ 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 + )) + }, } } }), ) .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 7900705..5b1a0f1 100644 --- a/Source/Fn/Summary.rs +++ b/Source/Fn/Summary.rs @@ -1,34 +1,40 @@ -/// Asynchronously generates a summary of differences between commits in a git repository. +/// Asynchronously generates a summary of differences between commits in a git +/// repository. /// /// This function performs the following steps: /// 1. Opens the specified git repository. /// 2. Retrieves and sorts the tags in the repository. /// 3. Identifies the first and last commits in the repository. -/// 4. Generates summaries of differences between the first commit and the last commit, as well as between each pair of consecutive tags. +/// 4. Generates summaries of differences between the first commit and the last +/// commit, as well as between each pair of consecutive tags. /// 5. Inserts the generated summaries into a DashMap. /// /// # Arguments /// /// * Entry - A string slice representing the path to the git repository. -/// * Option - A reference to a struct containing options for generating the diff summary. +/// * Option - A reference to a struct containing options for generating the +/// diff summary. /// /// # Returns /// -/// Returns a Result containing a DashMap with the generated summaries if successful, or a boxed dyn std::error::Error if an error occurs. +/// Returns a Result containing a DashMap with the generated summaries if +/// successful, or a boxed dyn std::error::Error if an error occurs. /// /// # Errors /// -/// This function will return an error if there are issues with opening the repository, retrieving tags, or generating the diff summaries. +/// This function will return an error if there are issues with opening the +/// repository, retrieving tags, or generating the diff summaries. /// /// # Example /// /// ```rust /// let options = crate::Struct::Summary::Difference::Struct { -/// Omit: vec!["(?i)\\.log$".to_string()], +/// Omit:vec!["(?i)\\.log$".to_string()], /// }; -/// let summary = Fn("/path/to/repo", &options).await.expect("Cannot generate summary."); +/// let summary = +/// Fn("/path/to/repo", &options).await.expect("Cannot generate summary."); /// for entry in summary.iter() { -/// println!("{:?}", entry); +/// println!("{:?}", entry); /// } /// ``` /// @@ -36,8 +42,8 @@ /// /// This function does not panic. pub async fn Fn( - Entry: &str, - Option: &crate::Struct::Summary::Difference::Struct, + Entry:&str, + Option:&crate::Struct::Summary::Difference::Struct, ) -> Result, Box> { let Summary = DashMap::new(); @@ -45,7 +51,7 @@ pub async fn Fn( Ok(Repository) => { let Name = Repository.tag_names(None)?; - let mut Date: Vec<(String, DateTime)> = Name + let mut Date:Vec<(String, DateTime)> = Name .iter() .filter_map(|Tag| { Tag.and_then(|Tag| { @@ -56,9 +62,12 @@ 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(), ) }) }) @@ -67,25 +76,39 @@ 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), ); } @@ -96,17 +119,22 @@ 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), ); } } - } + }, Err(_Error) => { eprintln!("Cannot Repository: {}", _Error); return Err(_Error.into()); - } + }, } Ok(Summary) diff --git a/Source/Fn/Summary/Difference.rs b/Source/Fn/Summary/Difference.rs index eeeef83..35b0e5a 100644 --- a/Source/Fn/Summary/Difference.rs +++ b/Source/Fn/Summary/Difference.rs @@ -1,36 +1,40 @@ /// Generates a diff summary between two commits in a git repository. /// -/// This function computes the differences between two specified commits in a git repository, -/// while filtering out changes to files that match a set of predefined patterns or user-specified -/// patterns to omit. The resulting diff is returned as a string. +/// This function computes the differences between two specified commits in a +/// git repository, while filtering out changes to files that match a set of +/// predefined patterns or user-specified patterns to omit. The resulting diff +/// is returned as a string. /// /// # Arguments /// /// * `Repository` - A reference to the git repository. /// * `Start` - A string slice representing the starting commit hash. /// * `End` - A string slice representing the ending commit hash. -/// * `Option` - A reference to a struct containing options for generating the diff summary. +/// * `Option` - A reference to a struct containing options for generating the +/// diff summary. /// /// # Returns /// -/// Returns a `Result` containing the diff summary as a `String` if successful, or a `git2::Error` -/// if an error occurs. +/// Returns a `Result` containing the diff summary as a `String` if successful, +/// or a `git2::Error` if an error occurs. /// /// # Errors /// -/// This function will return an error if there are issues with accessing the repository, parsing -/// the commit hashes, or generating the diff. +/// This function will return an error if there are issues with accessing the +/// repository, parsing the commit hashes, or generating the diff. /// /// # 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()], +/// Omit:vec!["(?i)\\.log$".to_string()], /// }; -/// let diff_summary = Fn(&repo, start_commit, end_commit, &options).expect("Cannot generate diff."); +/// let diff_summary = Fn(&repo, start_commit, end_commit, &options) +/// .expect("Cannot generate diff."); /// println!("{}", diff_summary); /// ``` /// @@ -38,10 +42,10 @@ /// /// This function will panic if the regex set cannot be created. pub fn Fn( - Repository: &git2::Repository, - Start: &str, - End: &str, - Option: &crate::Struct::Summary::Difference::Struct, + Repository:&git2::Repository, + Start:&str, + End:&str, + Option:&crate::Struct::Summary::Difference::Struct, ) -> Result { let mut Common = vec![ r"(?i)\.7z$", diff --git a/Source/Fn/Summary/First.rs b/Source/Fn/Summary/First.rs index f25a2ba..81d63c1 100644 --- a/Source/Fn/Summary/First.rs +++ b/Source/Fn/Summary/First.rs @@ -1,8 +1,9 @@ /// Retrieves the OID of the first commit in the repository. /// -/// This function initializes a revwalk on the given repository, pushes the HEAD reference onto the -/// revwalk, and sets the sorting mode to topological and reverse. It then retrieves the first commit -/// in the revwalk, which corresponds to the first commit in the repository. +/// This function initializes a revwalk on the given repository, pushes the HEAD +/// reference onto the revwalk, and sets the sorting mode to topological and +/// reverse. It then retrieves the first commit in the revwalk, which +/// corresponds to the first commit in the repository. /// /// # Arguments /// @@ -10,17 +11,20 @@ /// /// # Returns /// -/// Returns a `Result` containing the OID of the first commit if successful, or a `git2::Error` if an error occurs. +/// Returns a `Result` containing the OID of the first commit if successful, or +/// a `git2::Error` if an error occurs. /// /// # Errors /// -/// This function will return an error if there are issues with initializing the revwalk, pushing the HEAD reference, -/// setting the sorting mode, or retrieving the first commit. +/// This function will return an error if there are issues with initializing the +/// revwalk, pushing the HEAD reference, setting the sorting mode, or retrieving +/// the first commit. /// /// # 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); /// ``` @@ -28,7 +32,7 @@ /// # Panics /// /// This function does not panic. -pub fn Fn(Repository: &Repository) -> Result { +pub fn Fn(Repository:&Repository) -> Result { let mut Walk = Repository.revwalk()?; Walk.push_head()?; Walk.set_sorting(Sort::TOPOLOGICAL | Sort::REVERSE)?; diff --git a/Source/Fn/Summary/Group.rs b/Source/Fn/Summary/Group.rs index 892b7ba..2ce2181 100644 --- a/Source/Fn/Summary/Group.rs +++ b/Source/Fn/Summary/Group.rs @@ -1,28 +1,31 @@ /// Processes and prints summaries of differences. /// -/// This function takes an iterator of summaries, processes them to aggregate differences -/// by their associated messages, and then prints the aggregated results. The summaries -/// are expected to be in the form of a tuple containing an entry string and a `DashMap` -/// of differences. +/// This function takes an iterator of summaries, processes them to aggregate +/// differences by their associated messages, and then prints the aggregated +/// results. The summaries are expected to be in the form of a tuple containing +/// an entry string and a `DashMap` of differences. /// /// # Type Parameters /// -/// * `I` - An iterator type that yields items of type `(String, DashMap)`. +/// * `I` - An iterator type that yields items of type `(String, DashMap)`. /// /// # Arguments /// -/// * `summaries` - An iterator of summaries, where each summary is a tuple containing: +/// * `summaries` - An iterator of summaries, where each summary is a tuple +/// containing: /// - `Entry`: A `String` representing the entry associated with the summary. -/// - `Summary`: A `DashMap` where the key is a hash and the value is a tuple -/// containing a difference string and a message string. +/// - `Summary`: A `DashMap` where the key is a hash +/// and the value is a tuple containing a difference string and a message +/// string. /// /// # Example /// /// ```rust +/// use std::{cmp::Reverse, collections::HashSet}; +/// /// use dashmap::DashMap; -/// use std::collections::HashSet; /// use itertools::Itertools; -/// use std::cmp::Reverse; /// /// let mut summary1 = DashMap::new(); /// summary1.insert(1, ("diff1".to_string(), "message1".to_string())); @@ -31,8 +34,8 @@ /// summary2.insert(2, ("diff2".to_string(), "message2".to_string())); /// /// let summaries = vec![ -/// ("entry1".to_string(), summary1), -/// ("entry2".to_string(), summary2), +/// ("entry1".to_string(), summary1), +/// ("entry2".to_string(), summary2), /// ]; /// /// Fn(summaries); @@ -45,17 +48,16 @@ /// # Errors /// /// This function does not return errors. -pub fn Fn(Summary: I) +pub fn Fn(Summary:I) where - I: IntoIterator)>, -{ - let Output: DashMap> = DashMap::new(); + I: IntoIterator)>, { + let Output:DashMap> = DashMap::new(); for (Entry, Summary) in Summary { for (_, (Difference, Message)) in Summary.into_iter() { Output .entry(Message + " in " + &Entry) - .and_modify(|Existing: &mut HashSet| { + .and_modify(|Existing:&mut HashSet| { Existing.insert(Difference.clone()); }) .or_insert_with(|| { @@ -66,16 +68,19 @@ where } } - Output.into_iter().sorted_by(|(A, _), (B, _)| A.cmp(B)).for_each(|(Message, Difference)| { - println!("{}", Message); + 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)); - }); + Difference + .into_iter() + .sorted_by_key(|Difference| Reverse(Difference.len())) + .for_each(|Difference| println!("{}", Difference)); + }, + ); } +use std::{cmp::Reverse, collections::HashSet}; + use dashmap::DashMap; use itertools::Itertools; -use std::{cmp::Reverse, collections::HashSet}; diff --git a/Source/Fn/Summary/Insert.rs b/Source/Fn/Summary/Insert.rs index 9ae2a0b..8e17a46 100644 --- a/Source/Fn/Summary/Insert.rs +++ b/Source/Fn/Summary/Insert.rs @@ -1,14 +1,17 @@ /// Inserts a difference summary into the provided DashMap. /// -/// This function computes the hash of the given difference string and inserts it into the DashMap -/// along with the associated message. The hash is used as the key, and the value is a tuple -/// containing the difference string and the message. +/// This function computes the hash of the given difference string and inserts +/// it into the DashMap along with the associated message. The hash is used as +/// the key, and the value is a tuple containing the difference string and the +/// message. /// /// # Arguments /// -/// * `Summary` - A reference to a DashMap where the difference summary will be inserted. +/// * `Summary` - A reference to a DashMap where the difference summary will be +/// inserted. /// * `Difference` - A string representing the difference to be summarized. -/// * `Message` - A string representing the message associated with the difference. +/// * `Message` - A string representing the message associated with the +/// difference. /// /// # Example /// @@ -26,7 +29,11 @@ /// # 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/Fn/Summary/Insert/Hash.rs b/Source/Fn/Summary/Insert/Hash.rs index abf2d05..a4afa47 100644 --- a/Source/Fn/Summary/Insert/Hash.rs +++ b/Source/Fn/Summary/Insert/Hash.rs @@ -1,11 +1,13 @@ /// Computes the hash of the given input using the `DefaultHasher`. /// -/// This function takes any input that implements the `Hash` trait and computes its hash value -/// using the `DefaultHasher` from the standard library. The resulting hash is returned as a `u64`. +/// This function takes any input that implements the `Hash` trait and computes +/// its hash value using the `DefaultHasher` from the standard library. The +/// resulting hash is returned as a `u64`. /// /// # Arguments /// -/// * `Input` - A reference to the input value to be hashed. The input must implement the `Hash` trait. +/// * `Input` - A reference to the input value to be hashed. The input must +/// implement the `Hash` trait. /// /// # Returns /// @@ -14,8 +16,10 @@ /// # Example /// /// ```rust -/// use std::collections::hash_map::DefaultHasher; -/// use std::hash::{Hash, Hasher}; +/// use std::{ +/// collections::hash_map::DefaultHasher, +/// hash::{Hash, Hasher}, +/// }; /// /// let value = "example"; /// let hash = Fn(&value); @@ -29,7 +33,7 @@ /// # Errors /// /// This function does not return errors. -pub fn Fn(Input: &T) -> u64 { +pub fn Fn(Input:&T) -> u64 { let mut Output = DefaultHasher::new(); Input.hash(&mut Output); Output.finish() diff --git a/Source/Library.rs b/Source/Library.rs index bd54253..47e0fe8 100644 --- a/Source/Library.rs +++ b/Source/Library.rs @@ -4,9 +4,10 @@ #[tokio::main] /// The main entry point for the application. /// -/// This function initializes the command structure and executes the asynchronous function -/// defined within it. The function is marked with the `#[tokio::main]` attribute to enable -/// asynchronous execution using the Tokio runtime. +/// This function initializes the command structure and executes the +/// asynchronous function defined within it. The function is marked with the +/// `#[tokio::main]` attribute to enable asynchronous execution using the Tokio +/// runtime. /// /// # Panics /// @@ -16,13 +17,9 @@ /// /// ```rust /// #[tokio::main] -/// async fn main() { -/// (Struct::Binary::Command::Struct::Fn().Fn)().await -/// } +/// async fn main() { (Struct::Binary::Command::Struct::Fn().Fn)().await } /// ``` -async fn main() { - (Struct::Binary::Command::Struct::Fn().Fn)().await -} +async fn main() { (Struct::Binary::Command::Struct::Fn().Fn)().await } pub mod Fn; pub mod Struct; diff --git a/Source/Struct/Binary/Command.rs b/Source/Struct/Binary/Command.rs index 76dbb4f..ebce6ca 100644 --- a/Source/Struct/Binary/Command.rs +++ b/Source/Struct/Binary/Command.rs @@ -1,39 +1,47 @@ /// Represents the structure for binary command execution. /// -/// This struct holds various fields related to the command execution, including the separator for file paths -/// and a function to execute the command asynchronously. +/// This struct holds various fields related to the command execution, including +/// the separator for file paths and a function to execute the command +/// asynchronously. pub struct Struct { /// The separator used for file paths. - pub Separator: Option::Separator, + pub Separator:Option::Separator, /// A boxed asynchronous function that returns a pinned future. - pub Fn: Box Pin + Send + 'static>> + Send + 'static>, + pub Fn: Box< + dyn Fn() -> Pin + Send + 'static>> + + Send + + 'static, + >, } impl Struct { /// Creates a new instance of the Struct. /// - /// This function initializes the Struct with the default file path separator and an asynchronous function - /// that executes the command based on the provided options. The function determines whether to execute - /// the command in parallel or sequentially based on the `Parallel` flag in the options. + /// This function initializes the Struct with the default file path + /// separator and an asynchronous function that executes the command based + /// on the provided options. The function determines whether to execute the + /// command in parallel or sequentially based on the `Parallel` flag in the + /// options. /// /// # Returns /// /// Returns a new instance of Struct. pub fn Fn() -> Self { Self { - Separator: std::path::MAIN_SEPARATOR, - Fn: Box::new(|| { + 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 => { Parallel::Fn(Option).await; - } + }, false => { Sequential::Fn(Option).await; - } + }, }; }) }), @@ -41,9 +49,10 @@ impl Struct { } } -use futures::Future; use std::pin::Pin; +use futures::Future; + pub mod Entry; pub mod Option; diff --git a/Source/Struct/Binary/Command/Entry.rs b/Source/Struct/Binary/Command/Entry.rs index ff0469d..c5515f8 100644 --- a/Source/Struct/Binary/Command/Entry.rs +++ b/Source/Struct/Binary/Command/Entry.rs @@ -1,51 +1,60 @@ /// Represents the structure for binary command entries. /// -/// This struct holds various fields related to the command entries, including the entry paths, -/// parallel execution flag, pattern to match, separator for file paths, and omit patterns. +/// This struct holds various fields related to the command entries, including +/// the entry paths, parallel execution flag, pattern to match, separator for +/// file paths, and omit patterns. pub struct Struct { - /// A vector of vectors, where each inner vector contains the components of a file path. - pub Entry: Type, + /// A vector of vectors, where each inner vector contains the components of + /// a file path. + pub Entry:Type, /// A flag indicating whether to execute commands in parallel. - pub Parallel: Parallel, + pub Parallel:Parallel, /// A string pattern to match against the last element of each entry. - pub Pattern: Pattern, + pub Pattern:Pattern, /// The separator used for file paths. - pub Separator: Separator, + pub Separator:Separator, /// A vector of strings representing patterns to omit. - pub Omit: Omit, + pub Omit:Omit, } impl Struct { /// Creates a new instance of the Struct. /// - /// This function initializes the Struct with the provided options, generating the entry paths - /// and cloning the omit patterns, parallel flag, pattern, and separator from the options. + /// This function initializes the Struct with the provided options, + /// generating the entry paths and cloning the omit patterns, parallel + /// flag, pattern, and separator from the options. /// /// # Arguments /// - /// * `Option` - A reference to an Option struct containing initialization parameters. + /// * `Option` - A reference to an Option struct containing initialization + /// parameters. /// /// # Returns /// /// Returns a new instance of Struct. - pub fn Fn(Option: &Option) -> Self { + pub fn Fn(Option:&Option) -> Self { Self { - Entry: crate::Fn::Binary::Command::Entry::Fn(Option), - Omit: Option.Omit.clone(), - Parallel: Option.Parallel, - Pattern: Option.Pattern.clone(), - Separator: Option.Separator, + Entry:crate::Fn::Binary::Command::Entry::Fn(Option), + Omit:Option.Omit.clone(), + Parallel:Option.Parallel, + Pattern:Option.Pattern.clone(), + Separator:Option.Separator, } } } use crate::Struct::Binary::Command::Option::{ - Omit, Parallel, Pattern, Separator, Struct as Option, + Omit, + Parallel, + Pattern, + Separator, + Struct as Option, }; -/// Type alias for a vector of vectors, where each inner vector contains the components of a file path. +/// Type alias for a vector of vectors, where each inner vector contains the +/// components of a file path. pub type Type = Vec>; diff --git a/Source/Struct/Binary/Command/Option.rs b/Source/Struct/Binary/Command/Option.rs index 2a8f091..0ddfc52 100644 --- a/Source/Struct/Binary/Command/Option.rs +++ b/Source/Struct/Binary/Command/Option.rs @@ -1,53 +1,62 @@ /// Represents the options for binary command execution. /// -/// This struct holds various fields related to the command options, including exclude patterns, -/// omit patterns, parallel execution flag, pattern to match, root directory, and separator for file paths. +/// This struct holds various fields related to the command options, including +/// exclude patterns, omit patterns, parallel execution flag, pattern to match, +/// root directory, and separator for file paths. pub struct Struct { /// A vector of strings representing patterns to exclude. - pub Exclude: Vec, + pub Exclude:Vec, /// A vector of strings representing patterns to omit. - pub Omit: Vec, + pub Omit:Vec, /// A flag indicating whether to execute commands in parallel. - pub Parallel: Parallel, + pub Parallel:Parallel, /// A string pattern to match against the last element of each entry. - pub Pattern: Pattern, + pub Pattern:Pattern, /// The root directory to start the walk from. - pub Root: String, + pub Root:String, /// The separator used for file paths. - pub Separator: Separator, + pub Separator:Separator, } impl Struct { /// Creates a new instance of the Struct. /// - /// This function initializes the Struct with the provided options, generating the exclude patterns, - /// omit patterns, parallel flag, pattern, root directory, and separator from the options. + /// This function initializes the Struct with the provided options, + /// generating the exclude patterns, omit patterns, parallel flag, pattern, + /// root directory, and separator from the options. /// /// # Arguments /// - /// * `Option` - A reference to an Option struct containing initialization parameters. + /// * `Option` - A reference to an Option struct containing initialization + /// parameters. /// /// # Returns /// /// Returns a new instance of Struct. - pub fn Fn(Option { Separator, .. }: Option) -> Self { + pub fn Fn(Option { Separator, .. }:Option) -> Self { Self { - Exclude: Command() + Exclude:Command() .get_one::("Exclude") .expect("Cannot Exclude.") .split(" ") .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(), + 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(), Separator, - Omit: Command() + Omit:Command() .get_many::("Omit") .expect("Cannot Omit.") .map(|Omit| Omit.to_string()) @@ -56,7 +65,10 @@ 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 efe9627..b2e220b 100644 --- a/Source/Struct/Summary/Difference.rs +++ b/Source/Struct/Summary/Difference.rs @@ -9,11 +9,10 @@ /// # 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. - pub Omit: Vec, + pub Omit:Vec, } diff --git a/build.rs b/build.rs index 1f0de60..80f6a43 100644 --- a/build.rs +++ b/build.rs @@ -2,12 +2,12 @@ #[derive(Deserialize)] struct Toml { - package: Package, + package:Package, } #[derive(Deserialize)] struct Package { - version: String, + version:String, } fn main() { @@ -15,12 +15,15 @@ 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 ); } -use serde::Deserialize; use std::fs; + +use serde::Deserialize;