pvattest: Use map_or and map_or_else

Replace 'match .. { Some(v) => y, None/_ => x }' statements with
'Option::map_or_else' and 'Option::map_or'. See
https://rust-lang.github.io/rust-clippy/master/index.html#option_if_let_else.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2024-12-03 15:43:50 +01:00
committed by Jan Höppner
parent b1ca60f5ba
commit 6c75a06b12
2 changed files with 12 additions and 23 deletions

View File

@@ -56,10 +56,9 @@ impl Display for Response {
if self.valid { "" } else { "not " }
)?;
match &self.reason {
Some(r) => write!(f, "\n Reason: {r}\n ReferenceId: {}", self.reference_id),
None => Ok(()),
}
self.reason.as_ref().map_or(Ok(()), |r| {
write!(f, "\n Reason: {r}\n ReferenceId: {}", self.reference_id)
})
}
}

View File

@@ -37,27 +37,20 @@ impl Entry {
///
/// panics if `val` is larger than `max_size` bytes
fn from_slice(val: Option<&[u8]>, max_size: u32, offset: &mut u32) -> Self {
match val {
Some(val) => {
assert!(val.len() <= max_size as usize);
let size = val.len() as u32;
let res = Self::new(size, *offset);
*offset += size;
res
}
None => Self::default(),
}
val.map_or_else(Self::default, |val| {
assert!(val.len() <= max_size as usize);
let size = val.len() as u32;
let res = Self::new(size, *offset);
*offset += size;
res
})
}
/// # Panic
///
/// panics if `val` is larger than `max_size` bytes
fn from_exp(val: Option<u32>) -> Self {
if let Some(val) = val {
Self::new(val, 0)
} else {
Self::default()
}
val.map_or_else(Self::default, |val| Self::new(val, 0))
}
fn from_none() -> Self {
@@ -239,10 +232,7 @@ impl ExpOrData {
impl From<Option<u32>> for ExpOrData {
fn from(value: Option<u32>) -> Self {
match value {
Some(v) => Self::Exp(v),
None => Self::None,
}
value.map_or(Self::None, Self::Exp)
}
}