From ac0aa8aa5edef2e1a5c2e9b1954a636fedef20da Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Tue, 9 Aug 2022 16:18:21 +0000 Subject: [PATCH] vfio_user: fix two clippy warnings Signed-off-by: Wei Liu --- vfio_user/src/lib.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/vfio_user/src/lib.rs b/vfio_user/src/lib.rs index c46334236..f97769558 100644 --- a/vfio_user/src/lib.rs +++ b/vfio_user/src/lib.rs @@ -552,8 +552,7 @@ impl Client { cap_size, reply.header.message_size - size_of::() as u32 ); - let mut cap_data = Vec::with_capacity(cap_size as usize); - cap_data.resize(cap_data.capacity(), 0u8); + let mut cap_data = vec![0; cap_size as usize]; self.stream .read_exact(cap_data.as_mut_slice()) .map_err(Error::StreamRead)?; @@ -770,13 +769,9 @@ impl Client { } pub fn region(&self, region_index: u32) -> Option<&Region> { - for region in &self.regions { - if region.index == region_index { - return Some(region); - } - } - - None + self.regions + .iter() + .find(|®ion| region.index == region_index) } pub fn resettable(&self) -> bool {