|
13 | 13 | /// |
14 | 14 | /// If `self` is a single feature and multiple features are returned, `self` requires only one of them. |
15 | 15 | /// |
| 16 | + /// # Driver Requirements |
| 17 | + /// |
| 18 | + /// The driver MUST NOT accept a feature which requires another feature which was not accepted. |
| 19 | + /// |
| 20 | + /// # Device Requirements |
| 21 | + /// |
| 22 | + /// The device MUST NOT offer a feature which requires another feature which was not offered. |
| 23 | + /// |
16 | 24 | /// # Examples |
17 | 25 | /// |
18 | 26 | /// ``` |
|
52 | 60 | .filter(|requirements| !requirements.is_empty()) |
53 | 61 | .all(|requirements| self.intersects(requirements)) |
54 | 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 | + } |
55 | 107 | } |
56 | 108 |
|
57 | 109 | endian_bitflags! { |
@@ -498,6 +550,21 @@ pub mod net { |
498 | 550 |
|
499 | 551 | requirements |
500 | 552 | } |
| 553 | + |
| 554 | + fn recommendations(&self) -> Self { |
| 555 | + let mut recommendations = Self::empty(); |
| 556 | + |
| 557 | + for feature in self.iter() { |
| 558 | + let recommendation = match feature { |
| 559 | + Self::HASH_REPORT => Self::CTRL_VQ, |
| 560 | + Self::CTRL_RX_EXTRA => Self::CTRL_VQ, |
| 561 | + _ => Self::empty(), |
| 562 | + }; |
| 563 | + recommendations.insert(recommendation); |
| 564 | + } |
| 565 | + |
| 566 | + recommendations |
| 567 | + } |
501 | 568 | } |
502 | 569 | } |
503 | 570 |
|
|
0 commit comments