Skip to content

Commit

Permalink
Provide default fn impls in FromAttribute trait
Browse files Browse the repository at this point in the history
  • Loading branch information
DRiKE committed Feb 26, 2024
1 parent 422c2dc commit c565171
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
16 changes: 11 additions & 5 deletions src/bgp/path_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,21 @@ impl PaMap {


pub trait FromAttribute {
fn from_attribute(value: PathAttribute) -> Option<Self>
fn from_attribute(_value: PathAttribute) -> Option<Self>
where
Self: Sized;
fn attribute_type() -> Option<PathAttributeType>;
Self: Sized {
None
}

fn attribute_type() -> Option<PathAttributeType> {
None
}

}

impl From<AttributesMap> for PaMap {
fn from(value: AttributesMap) -> Self {
Self { attributes: value }
fn from(attributes: AttributesMap) -> Self {
Self { attributes }
}
}

Expand Down
34 changes: 4 additions & 30 deletions src/bgp/workshop/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::bgp::{
message::{nlri::Nlri, update_builder::StandardCommunitiesList},
path_attributes::{
ExtendedCommunitiesList, Ipv6ExtendedCommunitiesList,
LargeCommunitiesList, PathAttribute, PathAttributeType,
LargeCommunitiesList, PathAttribute,
},
};

Expand Down Expand Up @@ -241,29 +241,11 @@ impl<N: Clone + Hash + Debug> WorkshopAttribute<N> for Vec<Community> {
}
}

impl FromAttribute for Vec<Community> {
fn from_attribute(_value: PathAttribute) -> Option<Self> {
None
}

fn attribute_type() -> Option<PathAttributeType> {
None
}
}
impl FromAttribute for Vec<Community> { }

//------------ NlriWorkshop --------------------------------------------------

impl FromAttribute for crate::bgp::message::nlri::Nlri<Vec<u8>> {
fn from_attribute(_value: PathAttribute) -> Option<Self>
where
Self: Sized {
None
}

fn attribute_type() -> Option<PathAttributeType> {
None
}
}
impl FromAttribute for crate::bgp::message::nlri::Nlri<Vec<u8>> { }

impl<N: Clone + Hash> WorkshopAttribute<N> for crate::bgp::message::nlri::Nlri<Vec<u8>> {
fn retrieve(attrs: &PaMap) -> Option<Self>
Expand All @@ -286,15 +268,7 @@ impl<N: Clone + Hash> WorkshopAttribute<N> for crate::bgp::message::nlri::Nlri<V

//------------ NextHopWorkshop -----------------------------------------------

impl FromAttribute for crate::bgp::types::NextHop {
fn attribute_type() -> Option<PathAttributeType> {
None
}

fn from_attribute(_value: PathAttribute) -> Option<Self> {
None
}
}
impl FromAttribute for crate::bgp::types::NextHop { }

impl<N: Clone + Hash> WorkshopAttribute<N> for crate::bgp::types::NextHop {
fn retrieve(attrs: &PaMap) -> Option<Self> {
Expand Down

0 comments on commit c565171

Please sign in to comment.