summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuri Astrakhan <yuriastrakhan@gmail.com>2023-11-15 03:47:22 -0500
committerGitHub <noreply@github.com>2023-11-15 03:47:22 -0500
commit5eb4fbde5d7e41cd39dcb7c95e1bbf542e706cb0 (patch)
tree13b0ba47b78190b294b54d05eb4821306a6687f3
parenta6200640b9a074feb116b7808543c8cb73c8dd30 (diff)
chore: fix certain uninlined string format uses (#1310)
* Fixed uninlined args First ran this, and fixed a few more similar issues by hand ``` cargo clippy --workspace --fix --benches --tests --bins -- -A clippy::all -W clippy::uninlined_format_args ``` Note that in a few cases, format args were passed by ref - which is actually a tiny perf hit - compiler would not be able to optimize them. * revert change here since it contains a non-inlineable variable I'm not a fan of using it partially here * revert given the other formats above/below I would prefer keeping it like this --------- Co-authored-by: Clement Tsang <34804052+ClementTsang@users.noreply.github.com>
-rw-r--r--src/app/data_harvester/processes/linux.rs2
-rw-r--r--src/app/data_harvester/temperature/linux.rs2
-rw-r--r--src/app/layout_manager.rs6
-rw-r--r--src/app/process_killer.rs8
-rw-r--r--src/app/query.rs10
-rw-r--r--src/canvas.rs3
-rw-r--r--src/canvas/canvas_styling/colour_utils.rs12
-rw-r--r--src/canvas/widgets/basic_table_arrows.rs4
-rw-r--r--src/canvas/widgets/battery_display.rs4
-rw-r--r--src/canvas/widgets/mem_graph.rs8
-rw-r--r--src/canvas/widgets/network_basic.rs8
-rw-r--r--src/canvas/widgets/network_graph.rs4
-rw-r--r--src/components/tui_widget/time_chart.rs2
-rw-r--r--src/lib.rs4
-rw-r--r--src/options.rs5
-rw-r--r--src/utils/gen_util.rs16
-rw-r--r--src/widgets/disk_table.rs4
-rw-r--r--src/widgets/process_table/proc_widget_data.rs2
18 files changed, 46 insertions, 58 deletions
diff --git a/src/app/data_harvester/processes/linux.rs b/src/app/data_harvester/processes/linux.rs
index 89bf9db4..8f50823b 100644
--- a/src/app/data_harvester/processes/linux.rs
+++ b/src/app/data_harvester/processes/linux.rs
@@ -144,7 +144,7 @@ fn read_proc(
let truncated_name = stat.comm.as_str();
if let Ok(cmdline) = cmdline {
if cmdline.is_empty() {
- (format!("[{}]", truncated_name), truncated_name.to_string())
+ (format!("[{truncated_name}]"), truncated_name.to_string())
} else {
(
cmdline.join(" "),
diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs
index 8021bc8c..72ca9eef 100644
--- a/src/app/data_harvester/temperature/linux.rs
+++ b/src/app/data_harvester/temperature/linux.rs
@@ -123,7 +123,7 @@ fn counted_name(seen_names: &mut HashMap<String, u32>, name: String) -> String {
if let Some(count) = seen_names.get_mut(&name) {
*count += 1;
- format!("{name} ({})", *count)
+ format!("{name} ({count})")
} else {
seen_names.insert(name.clone(), 0);
name
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs
index 94e7f877..f5ed8eaa 100644
--- a/src/app/layout_manager.rs
+++ b/src/app/layout_manager.rs
@@ -1018,7 +1018,7 @@ impl std::str::FromStr for BottomWidgetType {
#[cfg(feature = "battery")]
{
Err(BottomError::ConfigError(format!(
- "\"{}\" is an invalid widget name.
+ "\"{s}\" is an invalid widget name.
Supported widget names:
+--------------------------+
@@ -1037,13 +1037,12 @@ Supported widget names:
| batt, battery |
+--------------------------+
",
- s
)))
}
#[cfg(not(feature = "battery"))]
{
Err(BottomError::ConfigError(format!(
- "\"{}\" is an invalid widget name.
+ "\"{s}\" is an invalid widget name.
Supported widget names:
+--------------------------+
@@ -1060,7 +1059,6 @@ Supported widget names:
| disk |
+--------------------------+
",
- s
)))
}
}
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs
index 106419ee..c68b81ab 100644
--- a/src/app/process_killer.rs
+++ b/src/app/process_killer.rs
@@ -75,14 +75,10 @@ pub fn kill_process_given_pid(pid: Pid, signal: usize) -> crate::utils::error::R
return if let Some(err_code) = err_code {
Err(BottomError::GenericError(format!(
- "Error code {} - {}",
- err_code, err,
+ "Error code {err_code} - {err}"
)))
} else {
- Err(BottomError::GenericError(format!(
- "Error code ??? - {}",
- err,
- )))
+ Err(BottomError::GenericError(format!("Error code ??? - {err}")))
};
}
diff --git a/src/app/query.rs b/src/app/query.rs
index 713e7d62..85858ddc 100644
--- a/src/app/query.rs
+++ b/src/app/query.rs
@@ -54,7 +54,7 @@ pub fn parse_query(
let mut rhs: Option<Box<And>> = None;
while let Some(queue_top) = query.front() {
- // debug!("OR QT: {:?}", queue_top);
+ // debug!("OR QT: {queue_top:?}");
if OR_LIST.contains(&queue_top.to_lowercase().as_str()) {
query.pop_front();
rhs = Some(Box::new(process_and(query)?));
@@ -90,7 +90,7 @@ pub fn parse_query(
let mut rhs: Option<Box<Prefix>> = None;
while let Some(queue_top) = query.front() {
- // debug!("AND QT: {:?}", queue_top);
+ // debug!("AND QT: {queue_top:?}");
if AND_LIST.contains(&queue_top.to_lowercase().as_str()) {
query.pop_front();
@@ -810,11 +810,11 @@ impl Prefix {
impl Debug for Prefix {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(or) = &self.or {
- f.write_fmt(format_args!("{:?}", or))
+ f.write_fmt(format_args!("{or:?}"))
} else if let Some(regex_prefix) = &self.regex_prefix {
- f.write_fmt(format_args!("{:?}", regex_prefix))
+ f.write_fmt(format_args!("{regex_prefix:?}"))
} else if let Some(compare_prefix) = &self.compare_prefix {
- f.write_fmt(format_args!("{:?}", compare_prefix))
+ f.write_fmt(format_args!("{compare_prefix:?}"))
} else {
f.write_fmt(format_args!(""))
}
diff --git a/src/canvas.rs b/src/canvas.rs
index 0cdd1f44..72890477 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -49,8 +49,7 @@ impl FromStr for ColourScheme {
"nord" => Ok(ColourScheme::Nord),
"nord-light" => Ok(ColourScheme::NordLight),
_ => Err(BottomError::ConfigError(format!(
- "\"{}\" is an invalid built-in color scheme.",
- s
+ "\"{s}\" is an invalid built-in color scheme."
))),
}
}
diff --git a/src/canvas/canvas_styling/colour_utils.rs b/src/canvas/canvas_styling/colour_utils.rs
index 7cb24203..5c39be74 100644
--- a/src/canvas/canvas_styling/colour_utils.rs
+++ b/src/canvas/canvas_styling/colour_utils.rs
@@ -70,8 +70,7 @@ pub fn str_to_colour(input_val: &str) -> error::Result<Color> {
}
} else {
Err(error::BottomError::ConfigError(format!(
- "value \"{}\" is not valid.",
- input_val
+ "value \"{input_val}\" is not valid.",
)))
}
}
@@ -80,8 +79,7 @@ fn convert_rgb_to_color(rgb_str: &str) -> error::Result<Color> {
let rgb_list = rgb_str.split(',').collect::<Vec<&str>>();
if rgb_list.len() != 3 {
return Err(error::BottomError::ConfigError(format!(
- "value \"{}\" is an invalid RGB colour. It must be a comma separated value with 3 integers from 0 to 255 (ie: \"255, 0, 155\").",
- rgb_str
+ "value \"{rgb_str}\" is an invalid RGB colour. It must be a comma separated value with 3 integers from 0 to 255 (ie: \"255, 0, 155\").",
)));
}
@@ -99,8 +97,7 @@ fn convert_rgb_to_color(rgb_str: &str) -> error::Result<Color> {
Ok(Color::Rgb(rgb[0], rgb[1], rgb[2]))
} else {
Err(error::BottomError::ConfigError(format!(
- "value \"{}\" contained invalid RGB values. It must be a comma separated value with 3 integers from 0 to 255 (ie: \"255, 0, 155\").",
- rgb_str
+ "value \"{rgb_str}\" contained invalid RGB values. It must be a comma separated value with 3 integers from 0 to 255 (ie: \"255, 0, 155\").",
)))
}
}
@@ -125,7 +122,7 @@ fn convert_name_to_colour(color_name: &str) -> error::Result<Color> {
"lightcyan" | "light cyan" => Ok(Color::LightCyan),
"white" => Ok(Color::White),
_ => Err(error::BottomError::ConfigError(format!(
- "\"{}\" is an invalid named color.
+ "\"{color_name}\" is an invalid named color.
The following are supported strings:
+--------+-------------+---------------------+
@@ -142,7 +139,6 @@ The following are supported strings:
| Blue | Light Green | |
+--------+-------------+---------------------+
",
- color_name
))),
}
}
diff --git a/src/canvas/widgets/basic_table_arrows.rs b/src/canvas/widgets/basic_table_arrows.rs
index 029a6e12..addd5207 100644
--- a/src/canvas/widgets/basic_table_arrows.rs
+++ b/src/canvas/widgets/basic_table_arrows.rs
@@ -95,7 +95,7 @@ impl Painter {
let left_arrow_text = vec![
Line::default(),
Line::from(Span::styled(
- format!("◄ {}", left_name),
+ format!("◄ {left_name}"),
self.colours.text_style,
)),
];
@@ -103,7 +103,7 @@ impl Painter {
let right_arrow_text = vec![
Line::default(),
Line::from(Span::styled(
- format!("{} ►", right_name),
+ format!("{right_name} ►"),
self.colours.text_style,
)),
];
diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs
index a43a72cb..611859a6 100644
--- a/src/canvas/widgets/battery_display.rs
+++ b/src/canvas/widgets/battery_display.rs
@@ -176,9 +176,9 @@ impl Painter {
let num_seconds = time.whole_seconds() - time.whole_minutes() * 60;
if num_hours > 0 {
- format!("{}h {}m {}s", time.whole_hours(), num_minutes, num_seconds,)
+ format!("{num_hours}h {num_minutes}m {num_seconds}s")
} else {
- format!("{}m {}s", num_minutes, num_seconds,)
+ format!("{num_minutes}m {num_seconds}s")
}
}
diff --git a/src/canvas/widgets/mem_graph.rs b/src/canvas/widgets/mem_graph.rs
index c0caa749..16f5c41d 100644
--- a/src/canvas/widgets/mem_graph.rs
+++ b/src/canvas/widgets/mem_graph.rs
@@ -50,7 +50,7 @@ impl Painter {
let mut points = Vec::with_capacity(size);
if let Some((label_percent, label_frac)) = &app_state.converted_data.mem_labels {
- let mem_label = format!("RAM:{}{}", label_percent, label_frac);
+ let mem_label = format!("RAM:{label_percent}{label_frac}");
points.push(GraphData {
points: &app_state.converted_data.mem_data,
style: self.colours.ram_style,
@@ -59,7 +59,7 @@ impl Painter {
}
#[cfg(not(target_os = "windows"))]
if let Some((label_percent, label_frac)) = &app_state.converted_data.cache_labels {
- let cache_label = format!("CHE:{}{}", label_percent, label_frac);
+ let cache_label = format!("CHE:{label_percent}{label_frac}");
points.push(GraphData {
points: &app_state.converted_data.cache_data,
style: self.colours.cache_style,
@@ -67,7 +67,7 @@ impl Painter {
});
}
if let Some((label_percent, label_frac)) = &app_state.converted_data.swap_labels {
- let swap_label = format!("SWP:{}{}", label_percent, label_frac);
+ let swap_label = format!("SWP:{label_percent}{label_frac}");
points.push(GraphData {
points: &app_state.converted_data.swap_data,
style: self.colours.swap_style,
@@ -76,7 +76,7 @@ impl Painter {
}
#[cfg(feature = "zfs")]
if let Some((label_percent, label_frac)) = &app_state.converted_data.arc_labels {
- let arc_label = format!("ARC:{}{}", label_percent, label_frac);
+ let arc_label = format!("ARC:{label_percent}{label_frac}");
points.push(GraphData {
points: &app_state.converted_data.arc_data,
style: self.colours.arc_style,
diff --git a/src/canvas/widgets/network_basic.rs b/src/canvas/widgets/network_basic.rs
index 5d7e2597..b877396f 100644
--- a/src/canvas/widgets/network_basic.rs
+++ b/src/canvas/widgets/network_basic.rs
@@ -38,10 +38,10 @@ impl Painter {
);
}
- let rx_label = format!("RX: {}", &app_state.converted_data.rx_display);
- let tx_label = format!("TX: {}", &app_state.converted_data.tx_display);
- let total_rx_label = format!("Total RX: {}", &app_state.converted_data.total_rx_display);
- let total_tx_label = format!("Total TX: {}", &app_state.converted_data.total_tx_display);
+ let rx_label = format!("RX: {}", app_state.converted_data.rx_display);
+ let tx_label = format!("TX: {}", app_state.converted_data.tx_display);
+ let total_rx_label = format!("Total RX: {}", app_state.converted_data.total_rx_display);
+ let total_tx_label = format!("Total TX: {}", app_state.converted_data.total_tx_display);
let net_text = vec![
Line::from(Span::styled(rx_label, self.colours.rx_style)),
diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs
index 5e6f71d1..5073fda6 100644
--- a/src/canvas/widgets/network_graph.rs
+++ b/src/canvas/widgets/network_graph.rs
@@ -413,13 +413,13 @@ fn adjust_network_data_point(
let base_unit = max_value_scaled;
let labels: Vec<String> = vec![
- format!("0{}{}", unit_prefix, unit_type),
+ format!("0{unit_prefix}{unit_type}"),
format!("{:.1}", base_unit * 0.5),
format!("{:.1}", base_unit),
format!("{:.1}", base_unit * 1.5),
]
.into_iter()
- .map(|s| format!("{:>5}", s)) // Pull 5 as the longest legend value is generally going to be 5 digits (if they somehow hit over 5 terabits per second)
+ .map(|s| format!("{s:>5}")) // Pull 5 as the longest legend value is generally going to be 5 digits (if they somehow hit over 5 terabits per second)
.collect();
(bumped_max_entry, labels)
diff --git a/src/components/tui_widget/time_chart.rs b/src/components/tui_widget/time_chart.rs
index e433bc16..403ef507 100644
--- a/src/components/tui_widget/time_chart.rs
+++ b/src/components/tui_widget/time_chart.rs
@@ -696,7 +696,7 @@ mod test {
for case in &cases {
let datasets = (0..10)
.map(|i| {
- let name = format!("Dataset #{}", i);
+ let name = format!("Dataset #{i}");
Dataset::default().name(name).data(&data)
})
.collect::<Vec<_>>();
diff --git a/src/lib.rs b/src/lib.rs
index 3ad1c0ec..1c804181 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -110,7 +110,7 @@ pub fn handle_mouse_event(event: MouseEvent, app: &mut App) {
pub fn handle_key_event_or_break(
event: KeyEvent, app: &mut App, reset_sender: &Sender<CollectionThreadEvent>,
) -> bool {
- // c_debug!("KeyEvent: {:?}", event);
+ // c_debug!("KeyEvent: {event:?}");
if event.modifiers.is_empty() {
// Required catch for searching - otherwise you couldn't search with q.
@@ -504,7 +504,7 @@ pub fn create_collection_thread(
}
if let Ok(message) = control_receiver.try_recv() {
- // trace!("Received message in collection thread: {:?}", message);
+ // trace!("Received message in collection thread: {message:?}");
match message {
CollectionThreadEvent::Reset => {
data_state.data.cleanup();
diff --git a/src/options.rs b/src/options.rs
index d220c319..8fe1fdd9 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -534,7 +534,7 @@ pub fn get_widget_layout(
// Confirm that we have at least ONE widget left - if not, error out!
if iter_id > 0 {
ret_bottom_layout.get_movement_mappings();
- // debug!("Bottom layout: {:#?}", ret_bottom_layout);
+ // debug!("Bottom layout: {ret_bottom_layout:#?}");
ret_bottom_layout
} else {
@@ -589,8 +589,7 @@ fn get_temperature(
"kelvin" | "k" => Ok(data_harvester::temperature::TemperatureType::Kelvin),
"celsius" | "c" => Ok(data_harvester::temperature::TemperatureType::Celsius),
_ => Err(BottomError::ConfigError(format!(
- "\"{}\" is an invalid temperature type, use \"<kelvin|k|celsius|c|fahrenheit|f>\".",
- temp_type
+ "\"{temp_type}\" is an invalid temperature type, use \"<kelvin|k|celsius|c|fahrenheit|f>\"."
))),
};
}
diff --git a/src/utils/gen_util.rs b/src/utils/gen_util.rs
index b71efc0c..3a729f2e 100644
--- a/src/utils/gen_util.rs
+++ b/src/utils/gen_util.rs
@@ -76,10 +76,10 @@ pub fn get_decimal_bytes(bytes: u64) -> (f64, &'static str) {
pub fn get_binary_prefix(quantity: u64, unit: &str) -> (f64, String) {
match quantity {
b if b < KIBI_LIMIT => (quantity as f64, unit.to_string()),
- b if b < MEBI_LIMIT => (quantity as f64 / 1024.0, format!("Ki{}", unit)),
- b if b < GIBI_LIMIT => (quantity as f64 / 1_048_576.0, format!("Mi{}", unit)),
- b if b < TERA_LIMIT => (quantity as f64 / 1_073_741_824.0, format!("Gi{}", unit)),
- _ => (quantity as f64 / 1_099_511_627_776.0, format!("Ti{}", unit)),
+ b if b < MEBI_LIMIT => (quantity as f64 / 1024.0, format!("Ki{unit}")),
+ b if b < GIBI_LIMIT => (quantity as f64 / 1_048_576.0, format!("Mi{unit}")),
+ b if b < TERA_LIMIT => (quantity as f64 / 1_073_741_824.0, format!("Gi{unit}")),
+ _ => (quantity as f64 / 1_099_511_627_776.0, format!("Ti{unit}")),
}
}
@@ -89,10 +89,10 @@ pub fn get_binary_prefix(quantity: u64, unit: &str) -> (f64, String) {
pub fn get_decimal_prefix(quantity: u64, unit: &str) -> (f64, String) {
match quantity {
b if b < KILO_LIMIT => (quantity as f64, unit.to_string()),
- b if b < MEGA_LIMIT => (quantity as f64 / 1000.0, format!("K{}", unit)),
- b if b < GIGA_LIMIT => (quantity as f64 / 1_000_000.0, format!("M{}", unit)),
- b if b < TERA_LIMIT => (quantity as f64 / 1_000_000_000.0, format!("G{}", unit)),
- _ => (quantity as f64 / 1_000_000_000_000.0, format!("T{}", unit)),
+ b if b < MEGA_LIMIT => (quantity as f64 / 1000.0, format!("K{unit}")),
+ b if b < GIGA_LIMIT => (quantity as f64 / 1_000_000.0, format!("M{unit}")),
+ b if b < TERA_LIMIT => (quantity as f64 / 1_000_000_000.0, format!("G{unit}")),
+ _ => (quantity as f64 / 1_000_000_000_000.0, format!("T{unit}")),
}
}
diff --git a/src/widgets/disk_table.rs b/src/widgets/disk_table.rs
index 45549e13..cdbefd19 100644
--- a/src/widgets/disk_table.rs
+++ b/src/widgets/disk_table.rs
@@ -69,7 +69,7 @@ impl DiskWidgetData {
pub fn free_percent_string(&self) -> KString {
match self.free_percent() {
- Some(val) => format!("{:.1}%", val).into(),
+ Some(val) => format!("{val:.1}%").into(),
None => "N/A".into(),
}
}
@@ -90,7 +90,7 @@ impl DiskWidgetData {
pub fn used_percent_string(&self) -> KString {
match self.used_percent() {
- Some(val) => format!("{:.1}%", val).into(),
+ Some(val) => format!("{val:.1}%").into(),
None => "N/A".into(),
}
}
diff --git a/src/widgets/process_table/proc_widget_data.rs b/src/widgets/process_table/proc_widget_data.rs
index 925bbe65..418d9997 100644
--- a/src/widgets/process_table/proc_widget_data.rs
+++ b/src/widgets/process_table/proc_widget_data.rs
@@ -101,7 +101,7 @@ impl PartialOrd for MemUsage {
impl Display for MemUsage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
- MemUsage::Percent(percent) => f.write_fmt(format_args!("{:.1}%", percent)),
+ MemUsage::Percent(percent) => f.write_fmt(format_args!("{percent:.1}%")),
MemUsage::Bytes(bytes) => f.write_str(&binary_byte_string(*bytes)),
}
}