Skip to content

Commit

Permalink
Allow (serde) attributes on typeenum! generated enums
Browse files Browse the repository at this point in the history
  • Loading branch information
DRiKE committed Nov 28, 2023
1 parent cad5c28 commit ff402c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/bgp/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde::{Serialize, Deserialize};

typeenum!(
/// AFI as used in BGP OPEN and UPDATE messages.
#[cfg_attr(feature = "serde", serde(from = "u16"))]
AFI, u16,
{
1 => Ipv4,
Expand All @@ -17,6 +18,7 @@ typeenum!(

typeenum!(
/// SAFI as used in BGP OPEN and UPDATE messages.
#[cfg_attr(feature = "serde", serde(from = "u8"))]
SAFI, u8,
{
1 => Unicast,
Expand Down
2 changes: 1 addition & 1 deletion src/util/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ macro_rules! typeenum {
$( $x1:pat => $y1:ident ),* $(,)*
})?
) => {
$(#[$attr])*
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
$(#[$attr])*
pub enum $name {
$($y),+,
$($($y1($ty),)?)?
Expand Down

0 comments on commit ff402c6

Please sign in to comment.