|
60 | 60 | .filter(|requirements| !requirements.is_empty()) |
61 | 61 | .all(|requirements| self.intersects(requirements)) |
62 | 62 | } |
| 63 | + |
| 64 | + /// Returns the feature that this feature recommends. |
| 65 | + /// |
| 66 | + /// If `self` is a single feature and multiple features are returned, `self` recommendns only one of them. |
| 67 | + /// |
| 68 | + /// # Driver Requirements |
| 69 | + /// |
| 70 | + /// The driver SHOULD NOT accept a feature which recommends another feature which was not accepted. |
| 71 | + /// |
| 72 | + /// # Device Requirements |
| 73 | + /// |
| 74 | + /// The device SHOULD NOT offer a feature which recommends another feature which was not offered. |
| 75 | + /// |
| 76 | + /// # Examples |
| 77 | + /// |
| 78 | + /// ``` |
| 79 | + /// # use virtio_spec as virtio; |
| 80 | + /// use virtio::FeatureBits; |
| 81 | + /// |
| 82 | + /// assert_eq!( |
| 83 | + /// virtio::net::F::HASH_REPORT.recommendations(), |
| 84 | + /// virtio::net::F::CTRL_VQ |
| 85 | + /// ); |
| 86 | + /// ``` |
| 87 | + fn recommendations(&self) -> Self { |
| 88 | + Self::empty() |
| 89 | + } |
| 90 | + |
| 91 | + /// Returns `true` if all internal feature recommendations are satisfied. |
| 92 | + /// |
| 93 | + /// # Examples |
| 94 | + /// |
| 95 | + /// ``` |
| 96 | + /// # use virtio_spec as virtio; |
| 97 | + /// use virtio::FeatureBits; |
| 98 | + /// |
| 99 | + /// assert!((virtio::net::F::HASH_REPORT | virtio::net::F::CTRL_VQ).recommendations_satisfied()); |
| 100 | + /// ``` |
| 101 | + fn recommendations_satisfied(&self) -> bool { |
| 102 | + self.iter() |
| 103 | + .map(|feature| feature.recommendations()) |
| 104 | + .filter(|recommendations| !recommendations.is_empty()) |
| 105 | + .all(|recommendations| self.intersects(recommendations)) |
| 106 | + } |
63 | 107 | } |
64 | 108 |
|
65 | 109 | endian_bitflags! { |
@@ -496,6 +540,21 @@ pub mod net { |
496 | 540 |
|
497 | 541 | requirements |
498 | 542 | } |
| 543 | + |
| 544 | + fn recommendations(&self) -> Self { |
| 545 | + let mut recommendations = Self::empty(); |
| 546 | + |
| 547 | + for feature in self.iter() { |
| 548 | + let recommendation = match feature { |
| 549 | + Self::HASH_REPORT => Self::CTRL_VQ, |
| 550 | + Self::CTRL_RX_EXTRA => Self::CTRL_VQ, |
| 551 | + _ => Self::empty(), |
| 552 | + }; |
| 553 | + recommendations.insert(recommendation); |
| 554 | + } |
| 555 | + |
| 556 | + recommendations |
| 557 | + } |
499 | 558 | } |
500 | 559 | } |
501 | 560 |
|
|
0 commit comments