Skip to content

Commit 7ef6bf6

Browse files
rwestphalcathay4t
authored andcommitted
impl From<IpAddr> for RouteVia
`From` is already implemented for `Ipv4Addr` and `Ipv6Addr`. This adds the missing `IpAddr` conversion for convenience. Signed-off-by: Renato Westphal <[email protected]>
1 parent 5bd5cc9 commit 7ef6bf6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/route/via.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3-
use std::net::{Ipv4Addr, Ipv6Addr};
3+
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
44

55
use netlink_packet_utils::{
66
traits::{Emitable, Parseable},
@@ -86,3 +86,12 @@ impl From<Ipv6Addr> for RouteVia {
8686
Self::Inet6(v)
8787
}
8888
}
89+
90+
impl From<IpAddr> for RouteVia {
91+
fn from(ip: IpAddr) -> Self {
92+
match ip {
93+
IpAddr::V4(ipv4) => Self::Inet(ipv4),
94+
IpAddr::V6(ipv6) => Self::Inet6(ipv6),
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)