Skip to content

Commit 9a274b9

Browse files
Serban Iorgaalxiord
authored andcommitted
[GuestMemory] add example for last_addr()
Signed-off-by: Serban Iorga <seriorga@amazon.com>
1 parent df6207f commit 9a274b9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/guest_memory.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,24 @@ pub trait GuestMemory {
302302
G: Fn(T, T) -> T;
303303

304304
/// Get maximum (inclusive) address managed by the region.
305+
///
306+
/// # Examples
307+
///
308+
/// ```
309+
/// # #[cfg(feature = "backend-mmap")]
310+
/// # use vm_memory::{Address, GuestAddress, GuestMemory, GuestMemoryMmap};
311+
///
312+
/// # #[cfg(feature = "backend-mmap")]
313+
/// # fn test_last_addr() -> Result<(), ()> {
314+
/// let start_addr = GuestAddress(0x1000);
315+
/// let mut gm = GuestMemoryMmap::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?;
316+
/// assert_eq!(start_addr.checked_add(0x3ff), Some(gm.last_addr()));
317+
/// Ok(())
318+
/// # }
319+
///
320+
/// # #[cfg(feature = "backend-mmap")]
321+
/// # test_last_addr();
322+
/// ```
305323
fn last_addr(&self) -> GuestAddress {
306324
self.map_and_fold(
307325
GuestAddress(0),

0 commit comments

Comments
 (0)