Skip to content

Commit

Permalink
simplifications thanks to clippy
Browse files Browse the repository at this point in the history
to make clippy more silent on my side and more focused
  • Loading branch information
bast committed Nov 19, 2024
1 parent dd8f815 commit ee358b4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/nvidia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl gpu::GPU for NvidiaGPU {

fn get_card_configuration(&mut self) -> Result<Vec<gpu::Card>, String> {
if self.info.is_none() {
self.info = Some(get_nvidia_configuration(&vec!["-a"]))
self.info = Some(get_nvidia_configuration(&["-a"]))
}
match self.info.as_ref().unwrap() {
Ok(data) => Ok(data
Expand All @@ -59,7 +59,7 @@ impl gpu::GPU for NvidiaGPU {

fn get_card_utilization(&mut self) -> Result<Vec<gpu::CardState>, String> {
if self.info.is_none() {
self.info = Some(get_nvidia_configuration(&vec!["-a"]))
self.info = Some(get_nvidia_configuration(&["-a"]))
}
match self.info.as_ref().unwrap() {
Ok(data) => Ok(data
Expand Down
14 changes: 7 additions & 7 deletions src/ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,16 +608,16 @@ fn add_key(
for c in cards {
let v = extract(c);
if !first {
vs = vs + "|";
vs += "|";
}
if v != "" {
if !v.is_empty() {
any = true;
vs = vs + &v;
}
first = false;
}
if any {
if s != "" {
if !s.is_empty() {
s += ",";
}
s + key + "=" + &vs
Expand Down Expand Up @@ -780,12 +780,12 @@ fn print_record(
}
if params.opts.load {
if let Some(cpu_secs) = per_cpu_secs {
if cpu_secs.len() > 0 {
if !cpu_secs.is_empty() {
fields.push(format!("load={}", encode_cpu_secs_base45el(cpu_secs)));
}
}
if let Some(gpu_info) = gpu_info {
if gpu_info != "" {
if !gpu_info.is_empty() {
fields.push(format!("gpuinfo={gpu_info}"));
}
}
Expand Down Expand Up @@ -830,7 +830,7 @@ fn encode_cpu_secs_base45el(cpu_secs: &[u64]) -> String {
for x in cpu_secs {
s += encode_u64_base45el(*x - base).as_str();
}
return s;
s
}

// The only character unused by the encoding, other than the ones we're not allowed to use, is '='.
Expand All @@ -845,7 +845,7 @@ fn encode_u64_base45el(mut x: u64) -> String {
s.push(SUBSEQUENT[(x % BASE) as usize] as char);
x /= BASE;
}
return s;
s
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/slurmjobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn show_slurm_jobs(window: &Option<u32>, span: &Option<String>) {
// Run sacct and parse the output.
match command::safe_command(
"sacct",
&vec![
&[
"-aP",
"-s",
&job_states.join(","),
Expand Down Expand Up @@ -128,7 +128,7 @@ fn check_ymd(s: &str) -> bool {
return false;
}
}
return k == 3;
k == 3
}

fn format_jobs(
Expand Down Expand Up @@ -160,7 +160,7 @@ fn format_jobs(
let mut output_line = "v=".to_string() + VERSION;
for (i, name) in field_names.iter().enumerate() {
let mut val = fields[i].to_string();
let is_zero = val == ""
let is_zero = val.is_empty()
|| (!uncontrolled_fields.contains(name) && zero_values.contains(val.as_str()));
if !is_zero {
if date_fields.contains(name) {
Expand Down
5 changes: 1 addition & 4 deletions src/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ fn do_show_system(
let mem_gib = (mem_by as f64 / GIB as f64).round() as i64;
let (mut cards, manufacturer) = match gpu::probe() {
Some(mut device) => (
match device.get_card_configuration() {
Ok(cards) => cards,
Err(_) => vec![],
},
device.get_card_configuration().unwrap_or_default(),
device.get_manufacturer(),
),
None => (vec![], "UNKNOWN".to_string()),
Expand Down
2 changes: 1 addition & 1 deletion src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn parse_date_and_time_no_tzo(s: &str) -> Result<libc::tm, String> {
}

fn parse_int_err(_e: ParseIntError) -> String {
return "Not an unsigned int value".to_string();
"Not an unsigned int value".to_string()
}

// Format a time as an ISO time stamp: yyyy-mm-ddThh:mm:ss+hh:mm
Expand Down

0 comments on commit ee358b4

Please sign in to comment.