Skip to content

Commit 415a712

Browse files
committed
Implement Deref for DeviceResources
Implement Deref for DeviceResources, so we could walk all resource entries in an Resources object. Signed-off-by: Liu Jiang <[email protected]>
1 parent e7ac3b6 commit 415a712

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/resources.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! 5) the VMM registers the new device onto corresponding device managers according the allocated
1313
//! resources.
1414
15+
use std::ops::Deref;
1516
use std::{u16, u32, u64};
1617

1718
/// Enumeration describing a device's resource constraints.
@@ -245,6 +246,14 @@ impl DeviceResources {
245246
}
246247
}
247248

249+
impl Deref for DeviceResources {
250+
type Target = Vec<Resource>;
251+
252+
fn deref(&self) -> &Self::Target {
253+
&self.0
254+
}
255+
}
256+
248257
#[cfg(test)]
249258
mod tests {
250259
use super::*;
@@ -431,4 +440,14 @@ mod tests {
431440
panic!("KVM slot resource constraint is invalid.");
432441
}
433442
}
443+
444+
#[test]
445+
fn test_resources_deref() {
446+
let resources = get_device_resource();
447+
let mut count = 0;
448+
for _res in resources.iter() {
449+
count += 1;
450+
}
451+
assert_eq!(count, resources.0.len());
452+
}
434453
}

0 commit comments

Comments
 (0)