diff options
author | Simon THOBY <git@nightmared.fr> | 2022-11-12 16:37:38 +0100 |
---|---|---|
committer | Simon THOBY <git@nightmared.fr> | 2022-11-12 16:37:38 +0100 |
commit | f8effdd348e38f51f6ec7b24c4c27e6602538445 (patch) | |
tree | 49334f265a27ea39f115d498780ecba3581728d3 /tests/lib.rs | |
parent | cc717f0aed28138ee1a422c790dd129bfc1bfdc1 (diff) |
tests: fix the NetlinkExpr ordering
Diffstat (limited to 'tests/lib.rs')
-rw-r--r-- | tests/lib.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/lib.rs b/tests/lib.rs index 0268b1a..4ca75ad 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -26,7 +26,7 @@ type NetLinkType = u16; #[error("empty data")] pub struct EmptyDataError; -#[derive(Debug, Clone, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, Ord)] pub enum NetlinkExpr { Nested(NetLinkType, Vec<NetlinkExpr>), Final(NetLinkType, Vec<u8>), @@ -35,7 +35,7 @@ pub enum NetlinkExpr { impl NetlinkExpr { pub fn to_raw(self) -> Vec<u8> { - match self { + match self.sort() { NetlinkExpr::Final(ty, val) => { let len = val.len() + 4; let mut res = Vec::with_capacity(len); @@ -109,6 +109,20 @@ impl PartialEq for NetlinkExpr { } } +impl PartialOrd for NetlinkExpr { + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { + match (self, other) { + ( + NetlinkExpr::Nested(k1, _) | NetlinkExpr::Final(k1, _), + NetlinkExpr::Nested(k2, _) | NetlinkExpr::Final(k2, _), + ) => k1.partial_cmp(k2), + (NetlinkExpr::List(v1), NetlinkExpr::List(v2)) => v1.partial_cmp(v2), + (_, NetlinkExpr::List(_)) => Some(std::cmp::Ordering::Less), + (NetlinkExpr::List(_), _) => Some(std::cmp::Ordering::Greater), + } + } +} + pub fn get_test_table() -> Table { Table::new(ProtocolFamily::Inet) .with_name(TABLE_NAME) |