Skip to content

Commit e097575

Browse files
committed
add naive default impl for GuestMemory::num_regions
Similar to find_region(), we can provide an inefficient default impl to make downstream impls of the trait less verbose in scenarios that really do not care (e.g. mock impls for tests). Signed-off-by: Patrick Roy <[email protected]>
1 parent 15606ea commit e097575

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/guest_memory.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ pub trait GuestMemory {
405405
type R: GuestMemoryRegion;
406406

407407
/// Returns the number of regions in the collection.
408-
fn num_regions(&self) -> usize;
408+
fn num_regions(&self) -> usize {
409+
self.iter().count()
410+
}
409411

410412
/// Returns the region containing the specified address or `None`.
411413
fn find_region(&self, addr: GuestAddress) -> Option<&Self::R> {

0 commit comments

Comments
 (0)