Skip to content

Commit a25d26f

Browse files
deastoecathay4t
authored andcommitted
neighbour: impl From<IpAddr> for NeighbourAddress
There are already impls for Ipv4Addr and Ipv6Addr, so for convenience and commonality with other *Address types add an impl for IpAddr too. Signed-off-by: Duncan Eastoe <[email protected]>
1 parent 2812ba1 commit a25d26f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/neighbour/address.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_core::{DecodeError, Emitable};
66

@@ -51,6 +51,15 @@ impl Emitable for NeighbourAddress {
5151
}
5252
}
5353

54+
impl From<IpAddr> for NeighbourAddress {
55+
fn from(v: IpAddr) -> Self {
56+
match v {
57+
IpAddr::V4(a) => a.into(),
58+
IpAddr::V6(a) => a.into(),
59+
}
60+
}
61+
}
62+
5463
impl From<Ipv4Addr> for NeighbourAddress {
5564
fn from(v: Ipv4Addr) -> Self {
5665
Self::Inet(v)

0 commit comments

Comments
 (0)