Skip to content

Commit a9f854b

Browse files
andreeaflorescualexandruag
authored andcommitted
add code examples for range inclusive
Signed-off-by: Andreea Florescu <[email protected]>
1 parent 9fb8bba commit a9f854b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ pub type Result<T> = result::Result<T, Error>;
136136

137137
/// A closed interval range [start, end].
138138
/// The range describes a memory slot which is assigned by the VMM to a device.
139+
///
140+
/// # Example
141+
///
142+
/// ```rust
143+
/// use vm_allocator::RangeInclusive;
144+
///
145+
/// let r = RangeInclusive::new(0x0, 0x100).unwrap();
146+
/// assert_eq!(r.len(), 0x101);
147+
/// assert_eq!(r.start(), 0x0);
148+
/// assert_eq!(r.end(), 0x100);
149+
///
150+
/// // Check if a region contains another region.
151+
/// let other = RangeInclusive::new(0x50, 0x80).unwrap();
152+
/// assert!(r.contains(&other));
153+
///
154+
/// // Check if a region overlaps with another one.
155+
/// let other = RangeInclusive::new(0x99, 0x150).unwrap();
156+
/// assert!(r.overlaps(&other));
157+
/// ```
139158
// This structure represents the key of the Node object in the interval tree implementation.
140159
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Ord, Debug)]
141160
pub struct RangeInclusive {

0 commit comments

Comments
 (0)