From 95ca7bb9c388106a6074050cea10b6cdac2c1c3b Mon Sep 17 00:00:00 2001 From: Gris Ge Date: Sun, 4 Jan 2026 15:01:00 +0800 Subject: [PATCH] link_mode: Support convert EthtoolLinkModeDuplex to u8 Signed-off-by: Gris Ge --- src/link_mode/attr.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/link_mode/attr.rs b/src/link_mode/attr.rs index 3cc19c3..c072d8f 100644 --- a/src/link_mode/attr.rs +++ b/src/link_mode/attr.rs @@ -23,7 +23,7 @@ const DUPLEX_HALF: u8 = 0x00; const DUPLEX_FULL: u8 = 0x01; const DUPLEX_UNKNOWN: u8 = 0xff; -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum EthtoolLinkModeDuplex { Half, Full, @@ -42,6 +42,17 @@ impl From for EthtoolLinkModeDuplex { } } +impl From for u8 { + fn from(v: EthtoolLinkModeDuplex) -> u8 { + match v { + EthtoolLinkModeDuplex::Half => DUPLEX_HALF, + EthtoolLinkModeDuplex::Full => DUPLEX_FULL, + EthtoolLinkModeDuplex::Unknown => DUPLEX_UNKNOWN, + EthtoolLinkModeDuplex::Other(d) => d, + } + } +} + #[derive(Debug, PartialEq, Eq, Clone)] pub enum EthtoolLinkModeAttr { Header(Vec),