diff --git a/src/format/mod.rs b/src/format/mod.rs index 06ef31f..570c1c9 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -85,7 +85,7 @@ impl HorizontalScale { } pub fn get_count(&self, units: usize, width: usize) -> Paint { - Green.paint(format!("{:width$}", units, width = width)) + Green.paint(format!("{units:width$}")) } pub fn get_scale(&self) -> usize { @@ -213,7 +213,7 @@ mod tests { let scale = HorizontalScale::new(0); assert_eq!(scale.get_scale(), 1); assert_eq!( - format!("{}", scale), + format!("{scale}"), format!("Each {BAR_CHAR} represents a count of 1\n") ); } diff --git a/src/main.rs b/src/main.rs index a51c365..c8a66af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,7 +61,7 @@ fn configure_output(option: &str, verbose: bool) { color_choice, ) { // We trigger this error when unit testing this fn - eprintln!("Error: {}", err); + eprintln!("Error: {err}"); } } @@ -117,7 +117,7 @@ fn histogram(matches: &ArgMatches) -> i32 { options.intervals = matches.value_of_t("intervals").unwrap(); let width = matches.value_of_t("width").unwrap(); let histogram = plot::Histogram::new(&vec, options); - print!("{:width$}", histogram, width = width); + print!("{histogram:width$}"); 0 } @@ -143,7 +143,7 @@ fn plot(matches: &ArgMatches) -> i32 { matches.value_of_t("height").unwrap(), precision, ); - print!("{}", plot); + print!("{plot}"); 0 } @@ -225,7 +225,7 @@ fn timehist(matches: &ArgMatches) -> i32 { let vec = reader.read(matches.value_of("input").unwrap()); if assert_data(&vec, 2) { let timehist = plot::TimeHistogram::new(matches.value_of_t("intervals").unwrap(), &vec); - print!("{:width$}", timehist, width = width); + print!("{timehist:width$}"); }; 0 } @@ -257,7 +257,7 @@ fn splittime(matches: &ArgMatches) -> i32 { string_list, &vec, ); - print!("{:width$}", timehist, width = width); + print!("{timehist:width$}"); }; 0 } diff --git a/src/plot/histogram.rs b/src/plot/histogram.rs index 3b82228..84b41a4 100644 --- a/src/plot/histogram.rs +++ b/src/plot/histogram.rs @@ -147,7 +147,7 @@ impl HistWriter { let width_count = ((hist.top as f64).log10().ceil() as usize).max(1); let horizontal_scale = HorizontalScale::new(hist.top / self.get_max_bar_len(width_range + width_count)); - writeln!(f, "{}", horizontal_scale)?; + writeln!(f, "{horizontal_scale}")?; for x in hist.vec.iter() { self.write_bucket(f, x, &horizontal_scale, width_range, width_count)?; } @@ -243,7 +243,7 @@ mod tests { -1.0, -1.1, 2.0, 2.0, 2.1, -0.9, 11.0, 11.2, 1.9, 1.99, 1.98, 1.97, 1.96, ]); Paint::disable(); - let display = format!("{}", hist); + let display = format!("{hist}"); assert!(display.contains("[-2.000 .. 0.500] [3] ∎∎∎\n")); assert!(display.contains("[ 0.500 .. 3.000] [8] ∎∎∎∎∎∎∎∎\n")); assert!(display.contains("[10.500 .. 13.000] [2] ∎∎\n")); @@ -261,7 +261,7 @@ mod tests { -1.0, -1.1, 2.0, 2.0, 2.1, -0.9, 11.0, 11.2, 1.9, 1.99, 1.98, 1.97, 1.96, ]); Paint::disable(); - let display = format!("{:2}", hist); + let display = format!("{hist:2}"); assert!(display.contains("[-2.000 .. 0.500] [3] ∎∎∎\n")); } @@ -279,7 +279,7 @@ mod tests { ]; let hist = Histogram::new(vector, HistogramOptions::default()); Paint::disable(); - let display = format!("{}", hist); + let display = format!("{hist}"); assert!(display.contains("[-12.0 M .. -10.4 M] [4] ∎∎∎∎\n")); assert!(display.contains("[ -2.6 M .. -1.1 M] [1] ∎\n")); assert!(display.contains("[ -1.1 M .. 0.5 M] [3] ∎∎∎\n")); diff --git a/src/plot/matchbar.rs b/src/plot/matchbar.rs index 243aa67..fc1213e 100644 --- a/src/plot/matchbar.rs +++ b/src/plot/matchbar.rs @@ -66,7 +66,7 @@ impl fmt::Display for MatchBar { self.vec.iter().map(|r| r.count).sum::() )), )?; - writeln!(f, "{}", horizontal_scale)?; + writeln!(f, "{horizontal_scale}")?; for row in self.vec.iter() { writeln!( f, @@ -98,7 +98,7 @@ mod tests { assert_eq!(mb.top_lenght, 8); assert_eq!(mb.top_values, 3); Paint::disable(); - let display = format!("{}", mb); + let display = format!("{mb}"); assert!(display.contains("[label1 ] [3] ∎∎∎\n")); assert!(display.contains("[label2 ] [1] ∎\n")); diff --git a/src/plot/splittimehist.rs b/src/plot/splittimehist.rs index 1be4534..a3d59b6 100644 --- a/src/plot/splittimehist.rs +++ b/src/plot/splittimehist.rs @@ -155,12 +155,12 @@ impl fmt::Display for SplitTimeHistogram { }) .collect(); - writeln!(f, "Matches: {}.", total)?; + writeln!(f, "Matches: {total}.")?; for (i, s) in self.strings.iter().enumerate() { let total = self.vec.iter().map(|r| r.count[i]).sum::(); - writeln!(f, "{}: {}.", COLORS[i].paint(s), total)?; + writeln!(f, "{}: {total}.", COLORS[i].paint(s))?; } - writeln!(f, "{}", horizontal_scale)?; + writeln!(f, "{horizontal_scale}")?; let ts_fmt = date_fmt_string(self.step.num_seconds()); for row in self.vec.iter() { self.fmt_row(f, row, horizontal_scale.get_scale(), &widths, ts_fmt)?; @@ -206,8 +206,8 @@ mod tests { vec!["one".to_string(), "two".to_string(), "three".to_string()], &vec, ); - println!("{}", th); - let display = format!("{}", th); + println!("{th}"); + let display = format!("{th}"); assert!(display.contains("Matches: 15")); assert!(display.contains("one: 1.")); assert!(display.contains("two: 2.")); diff --git a/src/plot/terms.rs b/src/plot/terms.rs index 2b25ed4..52cc6d1 100644 --- a/src/plot/terms.rs +++ b/src/plot/terms.rs @@ -46,12 +46,12 @@ impl fmt::Display for CommonTerms { let label_width = values.iter().fold(1, |acc, x| acc.max(x.0.len())); let horizontal_scale = HorizontalScale::new(counts[0].1 / width); let width_count = format!("{}", counts[0].1).len(); - writeln!(f, "{}", horizontal_scale)?; + writeln!(f, "{horizontal_scale}")?; for (term, count) in values.iter() { writeln!( f, "[{label}] [{count}] {bar}", - label = Blue.paint(format!("{:>width$}", term, width = label_width)), + label = Blue.paint(format!("{term:>label_width$}")), count = horizontal_scale.get_count(**count, width_count), bar = horizontal_scale.get_bar(**count) )?; @@ -69,7 +69,7 @@ mod tests { fn test_common_terms_empty() { let terms = CommonTerms::new(10); Paint::disable(); - let display = format!("{}", terms); + let display = format!("{terms}"); assert_eq!(display, "No data\n"); } @@ -86,9 +86,9 @@ mod tests { terms.observe(String::from("barbar")); } Paint::disable(); - let display = format!("{:10}", terms); + let display = format!("{terms:10}"); - println!("{}", display); + println!("{display}"); assert!(display.contains("[ foo] [100] ∎∎∎∎∎∎∎∎∎∎\n")); assert!(display.contains("[barbar] [ 20] ∎∎\n")); assert!(!display.contains("arr")); diff --git a/src/plot/timehist.rs b/src/plot/timehist.rs index 935be0d..a60594d 100644 --- a/src/plot/timehist.rs +++ b/src/plot/timehist.rs @@ -108,7 +108,7 @@ impl fmt::Display for TimeHistogram { self.vec.iter().map(|r| r.count).sum::() )), )?; - writeln!(f, "{}", horizontal_scale)?; + writeln!(f, "{horizontal_scale}")?; let ts_fmt = date_fmt_string(self.step.num_seconds()); for row in self.vec.iter() { writeln!( @@ -139,7 +139,7 @@ mod tests { DateTime::parse_from_rfc3339("2023-04-15T04:25:00+00:00").unwrap(), ]; let th = TimeHistogram::new(3, &vec); - let display = format!("{}", th); + let display = format!("{th}"); assert!(display.contains("Matches: 5")); assert!(display.contains("represents a count of 1")); assert!(display.contains("[2021-04-15 04:25:00] [1] ∎\n")); @@ -156,7 +156,7 @@ mod tests { DateTime::parse_from_rfc3339("2022-04-15T04:25:00.006+00:00").unwrap(), ]; let th = TimeHistogram::new(4, &vec); - let display = format!("{}", th); + let display = format!("{th}"); assert!(display.contains("Matches: 3")); assert!(display.contains("represents a count of 1")); assert!(display.contains("[04:25:00.001000] [2] ∎∎\n")); @@ -173,7 +173,7 @@ mod tests { DateTime::parse_from_rfc3339("2022-04-15T04:25:00.001+00:00").unwrap(), ]; let th = TimeHistogram::new(4, &vec); - let display = format!("{}", th); + let display = format!("{th}"); assert!(display.contains("Matches: 2")); assert!(display.contains("represents a count of 1")); assert!(display.contains("[04:25:00.001000] [2] ∎∎\n")); diff --git a/src/plot/xy.rs b/src/plot/xy.rs index e670092..bfb91bc 100644 --- a/src/plot/xy.rs +++ b/src/plot/xy.rs @@ -151,7 +151,7 @@ mod tests { let mut plot = XyPlot::new_with_stats(3, 5, stats, Some(3)); plot.load(&[-1.0, 0.0, 1.0, 2.0, 3.0, 4.0, -1.0]); Paint::disable(); - let display = format!("{}", plot); + let display = format!("{plot}"); assert!(display.contains("[ 3.000] ● ")); assert!(display.contains("[ 2.000] ")); assert!(display.contains("[ 1.000] ● ")); @@ -163,7 +163,7 @@ mod tests { let vector = &[1000000.0, -1000000.0, -2000000.0, -4000000.0]; let plot = XyPlot::new(vector, 3, 5, None); Paint::disable(); - let display = format!("{}", plot); + let display = format!("{plot}"); assert!(display.contains("[ 0 K] ● ")); assert!(display.contains("[-1000 K] ● ")); assert!(display.contains("[-2000 K] ● ")); diff --git a/src/read/dateparser.rs b/src/read/dateparser.rs index fc18b6f..4a1e3bc 100644 --- a/src/read/dateparser.rs +++ b/src/read/dateparser.rs @@ -54,7 +54,7 @@ impl LogDateParser { break; } } - Err(format!("Could not parse a timestamp in {}", log_line)) + Err(format!("Could not parse a timestamp in {log_line}")) } fn new_with_format(log_line: &str, format_string: &str) -> Result { diff --git a/src/stats/mod.rs b/src/stats/mod.rs index 342307f..fea34b2 100644 --- a/src/stats/mod.rs +++ b/src/stats/mod.rs @@ -98,7 +98,7 @@ mod tests { fn test_display() { let stats = Stats::new(&[1.1, 3.3, 2.2], Some(3)); Paint::disable(); - let display = format!("{}", stats); + let display = format!("{stats}"); assert!(display.contains("Samples = 3")); assert!(display.contains("Min = 1.100")); assert!(display.contains("Max = 3.300")); @@ -109,7 +109,7 @@ mod tests { fn test_big_num() { let stats = Stats::new(&[123456789.1234, 123456788.1234], None); Paint::disable(); - let display = format!("{}", stats); + let display = format!("{stats}"); assert!(display.contains("Samples = 2")); assert!(display.contains("Min = 123456788.123")); assert!(display.contains("Max = 123456789.123"));