Skip to main content

Library/Fn/Binary/Command/
Sequential.rs

1/// Asynchronously processes entries to generate summaries and outputs the
2/// results sequentially.
3///
4/// This function performs the following steps:
5/// 1. Filters and processes the provided entries based on the given pattern and
6///    separator.
7/// 2. Spawns asynchronous tasks to generate summaries for each entry.
8/// 3. Collects the results and outputs them.
9///
10/// # Arguments
11///
12/// * `Option` - A struct containing the following fields:
13///   - `Entry`: A vector of vectors, where each inner vector contains the
14///     components of a file path.
15///   - `Separator`: A character used to join the components of the file path.
16///   - `Pattern`: A string pattern to match against the last element of each
17///     entry.
18///   - `Omit`: A vector of strings representing patterns to omit.
19///
20/// # Example
21///
22/// ```rust
23/// let options = Option {
24/// 	Entry:vec![vec!["path".to_string(), "to".to_string(), "file.git".to_string()]],
25/// 	Separator:'/',
26/// 	Pattern:".git".to_string(),
27/// 	Omit:vec!["target".to_string()],
28/// };
29/// Fn(options).await;
30/// ```
31///
32/// # Errors
33///
34/// This function will log errors if it fails to generate summaries or send
35/// results.
36pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }:Option) {
37	let Queue = futures::future::join_all(
38		Entry
39			.into_iter()
40			.filter_map(|Entry| {
41				Entry
42					.last()
43					.filter(|Last| *Last == &Pattern)
44					.map(|_| Entry[0..Entry.len() - 1].join(&Separator.to_string()))
45			})
46			.map(|Entry| {
47				let Omit = Omit.clone();
48
49				async move {
50					match crate::Fn::Summary::Fn(&Entry, &crate::Struct::Summary::Difference::Struct { Omit }).await {
51						Ok(Summary) => Ok((Entry, Summary)),
52						Err(_Error) => Err(format!("Error generating summary for {}: {}", Entry, _Error)),
53					}
54				}
55			}),
56	)
57	.await;
58
59	crate::Fn::Summary::Group::Fn(Queue.into_iter().filter_map(Result::ok).collect::<Vec<_>>());
60}
61
62use crate::Struct::Binary::Command::Entry::Struct as Option;