sys_util: Combine GuestMemory::with_regions and with_regions_mut

Every implementation of Fn also implements FnMut, so if some callback
can be passed to GuestMemory::with_regions then it could also have been
passed to GuestMemory::with_regions_mut.

This CL removes GuestMemory::with_regions and renames with_regions_mut
to with_regions.

TEST=cargo check

Change-Id: Ia4f168ff4eb4d45a5ee8f9413821ae244fb72ee1
Reviewed-on: https://chromium-review.googlesource.com/1378688
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
This commit is contained in:
David Tolnay 2018-12-14 13:46:48 -08:00 committed by chrome-bot
parent 63bc050f5a
commit 1dda82e8b2
2 changed files with 2 additions and 18 deletions

View file

@ -142,23 +142,7 @@ impl GuestMemory {
}
/// Perform the specified action on each region's addresses.
pub fn with_regions<F, E>(&self, cb: F) -> result::Result<(), E>
where
F: Fn(usize, GuestAddress, usize, usize) -> result::Result<(), E>,
{
for (index, region) in self.regions.iter().enumerate() {
cb(
index,
region.guest_base,
region.mapping.size(),
region.mapping.as_ptr() as usize,
)?;
}
Ok(())
}
/// Perform the specified action on each region's addresses mutably.
pub fn with_regions_mut<F, E>(&self, mut cb: F) -> result::Result<(), E>
pub fn with_regions<F, E>(&self, mut cb: F) -> result::Result<(), E>
where
F: FnMut(usize, GuestAddress, usize, usize) -> result::Result<(), E>,
{

View file

@ -111,7 +111,7 @@ pub trait Vhost: AsRawFd + std::marker::Sized {
let _ = self
.mem()
.with_regions_mut::<_, ()>(|index, guest_addr, size, host_addr| {
.with_regions::<_, ()>(|index, guest_addr, size, host_addr| {
vhost_regions[index] = virtio_sys::vhost_memory_region {
guest_phys_addr: guest_addr.offset() as u64,
memory_size: size as u64,