Nightly clippy: overcomplicated unwrap_or

This commit is contained in:
sholderbach 2024-07-26 10:41:56 +02:00
parent 0450d16c37
commit cb0247f7ce
2 changed files with 20 additions and 48 deletions

View File

@ -156,58 +156,34 @@ fn create_history_record(idx: usize, entry: HistoryItem, long: bool, head: Span)
//2. Create a record of either short or long columns and values //2. Create a record of either short or long columns and values
let item_id_value = Value::int( let item_id_value = Value::int(
match entry.id { entry
Some(id) => { .id
let ids = id.to_string(); .and_then(|id| id.to_string().parse::<i64>().ok())
match ids.parse::<i64>() { .unwrap_or_default(),
Ok(i) => i,
_ => 0i64,
}
}
None => 0i64,
},
head, head,
); );
let start_timestamp_value = Value::string( let start_timestamp_value = Value::string(
match entry.start_timestamp { entry
Some(time) => time.to_string(), .start_timestamp
None => "".into(), .map(|time| time.to_string())
}, .unwrap_or_default(),
head, head,
); );
let command_value = Value::string(entry.command_line, head); let command_value = Value::string(entry.command_line, head);
let session_id_value = Value::int( let session_id_value = Value::int(
match entry.session_id { entry
Some(sid) => { .session_id
let sids = sid.to_string(); .and_then(|id| id.to_string().parse::<i64>().ok())
match sids.parse::<i64>() { .unwrap_or_default(),
Ok(i) => i,
_ => 0i64,
}
}
None => 0i64,
},
head,
);
let hostname_value = Value::string(
match entry.hostname {
Some(host) => host,
None => "".into(),
},
head,
);
let cwd_value = Value::string(
match entry.cwd {
Some(cwd) => cwd,
None => "".into(),
},
head, head,
); );
let hostname_value = Value::string(entry.hostname.unwrap_or_default(), head);
let cwd_value = Value::string(entry.cwd.unwrap_or_default(), head);
let duration_value = Value::duration( let duration_value = Value::duration(
match entry.duration { entry
Some(d) => d.as_nanos().try_into().unwrap_or(0), .duration
None => 0, .and_then(|d| d.as_nanos().try_into().ok())
}, .unwrap_or(0),
head, head,
); );
let exit_status_value = Value::int(entry.exit_status.unwrap_or(0), head); let exit_status_value = Value::int(entry.exit_status.unwrap_or(0), head);

View File

@ -150,13 +150,9 @@ fn fill(
FillAlignment::Left FillAlignment::Left
}; };
let width = if let Some(arg) = width_arg { arg } else { 1 }; let width = width_arg.unwrap_or(1);
let character = if let Some(arg) = character_arg { let character = character_arg.unwrap_or_else(|| " ".to_string());
arg
} else {
" ".to_string()
};
let arg = Arguments { let arg = Arguments {
width, width,