Skip to content

Commit

Permalink
Merge pull request #3 from ChocolateLoverRaj:unwrap-or-default
Browse files Browse the repository at this point in the history
Use unwrap_or_default where possible
  • Loading branch information
lleyton authored Jun 3, 2024
2 parents e82fd83 + ec826e7 commit ac41eb0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions crosec/src/commands/get_chip_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub fn ec_cmd_get_chip_info() -> EcCmdResult<(String, String, String)> {
let result = ec_command(CrosEcCmd::GetChipInfo, 0, params_slice, EcInterface::Dev(String::from("/dev/cros_ec")))?;
let response = bytemuck::from_bytes::<EcResponseGetChipInfo>(&result);

let vendor = String::from_utf8(response.vendor.to_vec()).unwrap_or(String::from(""));
let name = String::from_utf8(response.name.to_vec()).unwrap_or(String::from(""));
let revision = String::from_utf8(response.revision.to_vec()).unwrap_or(String::from(""));
let vendor = String::from_utf8(response.vendor.to_vec()).unwrap_or_default();
let name = String::from_utf8(response.name.to_vec()).unwrap_or_default();
let revision = String::from_utf8(response.revision.to_vec()).unwrap_or_default();

Ok((vendor, name, revision))
}
4 changes: 2 additions & 2 deletions crosec/src/commands/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn ec_cmd_version() -> EcCmdResult<(String, String, String, String, String)>
result.resize(size_of::<EcResponseVersionV1>(), Default::default());
let response = bytemuck::from_bytes::<EcResponseVersionV1>(&result);

let ro_ver = String::from_utf8(response.version_string_ro.to_vec()).unwrap_or(String::from(""));
let rw_ver = String::from_utf8(response.version_string_rw.to_vec()).unwrap_or(String::from(""));
let ro_ver = String::from_utf8(response.version_string_ro.to_vec()).unwrap_or_default();
let rw_ver = String::from_utf8(response.version_string_rw.to_vec()).unwrap_or_default();

let image = match FromPrimitive::from_u32(response.current_image) {
Some(EcImage::Unknown) => String::from("Unknown"),
Expand Down

0 comments on commit ac41eb0

Please sign in to comment.