vmm: leverage Iterator::find() to get KVM extension capability
This brings minor improvement, to leverage Iterator::find() instead
`if...else`, and destruct it for next cases.
@@ -127,16 +127,19 @@ impl KvmContext {
let capabilities = vec![Irqchip, Ioeventfd, Irqfd, UserMemory, ArmPsci02];
// Check that all desired capabilities are supported.
- for capability in capabilities.iter() {
- if !kvm.check_extension(*capability) {
- return Err(Error::KvmCap(*capability));
- }
- }
-
+ match capabilities
+ .iter()
+ .find(|&capability| !kvm.check_extension(*capability))
+ {
+ None => {
let max_memslots = kvm.get_nr_memslots();
Ok(KvmContext { kvm, max_memslots })
}
+ Some(c) => Err(Error::KvmCap(*c)),
+ }
+ }
+
pub fn fd(&self) -> &Kvm {
&self.kvm
}
