File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -688,6 +688,34 @@ impl From<BondAllPortActive> for u8 {
688688 }
689689}
690690
691+ impl std:: fmt:: Display for BondAllPortActive {
692+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
693+ match self {
694+ BondAllPortActive :: Dropped => f. write_str ( "dropped" ) ,
695+ BondAllPortActive :: Delivered => f. write_str ( "delivered" ) ,
696+ BondAllPortActive :: Other ( v) => write ! ( f, "{v}" ) ,
697+ }
698+ }
699+ }
700+
701+ impl std:: str:: FromStr for BondAllPortActive {
702+ type Err = DecodeError ;
703+
704+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
705+ Ok ( match s {
706+ "dropped" => Self :: Dropped ,
707+ "delivered" => Self :: Delivered ,
708+ "0" => Self :: Dropped ,
709+ "1" => Self :: Delivered ,
710+ _ => {
711+ return Err ( DecodeError :: from ( format ! (
712+ "unknown bond all ports active: {s}"
713+ ) ) )
714+ }
715+ } )
716+ }
717+ }
718+
691719const AD_LACP_SLOW : u8 = 0 ;
692720const AD_LACP_FAST : u8 = 1 ;
693721
Original file line number Diff line number Diff line change @@ -324,3 +324,20 @@ fn test_bond_lacp_rate_from_str() {
324324 assert_eq ! ( BondLacpRate :: Fast , "fast" . parse( ) . unwrap( ) ) ;
325325 assert ! ( BondLacpRate :: from_str( "bogus" ) . is_err( ) ) ;
326326}
327+
328+ #[ test]
329+ fn test_bond_all_ports_active_from_str ( ) {
330+ use std:: str:: FromStr ;
331+ assert_eq ! ( BondAllPortActive :: Dropped , "dropped" . parse( ) . unwrap( ) ) ;
332+ assert_eq ! ( BondAllPortActive :: Delivered , "delivered" . parse( ) . unwrap( ) ) ;
333+ assert_eq ! ( BondAllPortActive :: Dropped , "0" . parse( ) . unwrap( ) ) ;
334+ assert_eq ! ( BondAllPortActive :: Delivered , "1" . parse( ) . unwrap( ) ) ;
335+ assert ! ( BondAllPortActive :: from_str( "bogus" ) . is_err( ) ) ;
336+ }
337+
338+ #[ test]
339+ fn test_bond_all_ports_active_display ( ) {
340+ assert_eq ! ( "dropped" , BondAllPortActive :: Dropped . to_string( ) ) ;
341+ assert_eq ! ( "delivered" , BondAllPortActive :: Delivered . to_string( ) ) ;
342+ assert_eq ! ( "255" , BondAllPortActive :: Other ( 255 ) . to_string( ) ) ;
343+ }
You can’t perform that action at this time.
0 commit comments