From ec826e7da92331a4250d1a21222f2859cfaa4af3 Mon Sep 17 00:00:00 2001 From: Rajas Paranjpe <52586855+ChocolateLoverRaj@users.noreply.github.com> Date: Wed, 15 May 2024 19:16:30 -0700 Subject: [PATCH] Use unwrap_or_default where possible --- crosec/src/commands/get_chip_info.rs | 6 +++--- crosec/src/commands/version.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crosec/src/commands/get_chip_info.rs b/crosec/src/commands/get_chip_info.rs index cd6aefd..b97841c 100644 --- a/crosec/src/commands/get_chip_info.rs +++ b/crosec/src/commands/get_chip_info.rs @@ -23,9 +23,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: EcResponseGetChipInfo = unsafe { std::ptr::read(result.as_ptr() as *const _) }; - 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)) } diff --git a/crosec/src/commands/version.rs b/crosec/src/commands/version.rs index 9cc6408..81f4c21 100644 --- a/crosec/src/commands/version.rs +++ b/crosec/src/commands/version.rs @@ -42,8 +42,8 @@ pub fn ec_cmd_version() -> EcCmdResult<(String, String, String, String, String)> let result = ec_command(CrosEcCmd::Version, 0, params_slice, EcInterface::Dev(String::from("/dev/cros_ec")))?; let response: EcResponseVersionV1 = unsafe { std::ptr::read(result.as_ptr() as *const _) }; - 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"),