Skip to content

Commit c75dfa8

Browse files
committed
net-api: change TryFrom<IpAddress> to just From
It turns out, the TryFrom impl for smoltcp's IpAddress can't fail. This changed in 2023 with the upgrade to smoltcp 0.9, which made the shape of IpAddress depend on which protocol features we'd selected, removing the "unreachable" variants. This commit converts the impl to From, making it clear that it can't fail and eliminating an unwrap at its (apparently single) use site.
1 parent 837813b commit c75dfa8

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

task/net-api/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,12 @@ impl From<Address> for smoltcp::wire::IpAddress {
250250
}
251251

252252
#[cfg(feature = "use-smoltcp")]
253-
impl TryFrom<smoltcp::wire::IpAddress> for Address {
254-
type Error = AddressUnspecified;
255-
256-
fn try_from(a: smoltcp::wire::IpAddress) -> Result<Self, Self::Error> {
253+
impl From<smoltcp::wire::IpAddress> for Address {
254+
fn from(a: smoltcp::wire::IpAddress) -> Self {
257255
use smoltcp::wire::IpAddress;
258256

259257
match a {
260-
IpAddress::Ipv6(a) => Ok(Self::Ipv6(a.into())),
258+
IpAddress::Ipv6(a) => Self::Ipv6(a.into()),
261259
}
262260
}
263261
}

task/net/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ where
718718
return Ok(vlan.device.make_meta(
719719
endp.port,
720720
body_len,
721-
endp.addr.try_into().map_err(|_| ()).unwrap(),
721+
endp.addr.into(),
722722
));
723723
}
724724
Err(udp::RecvError::Exhausted) => {

0 commit comments

Comments
 (0)