Mercurial > crates > systemd-socket
comparison src/lib.rs @ 11:13e2a5545167
Implement From conversions
This implements same `From<T>` conversions that `std` does.
author | Martin Habovstiak <martin.habovstiak@gmail.com> |
---|---|
date | Sun, 29 Nov 2020 14:11:19 +0100 |
parents | 4fb70ca820a6 |
children | f740dadd2948 |
comparison
equal
deleted
inserted
replaced
10:c9f42be465ca | 11:13e2a5545167 |
---|---|
304 Systemd(Never), | 304 Systemd(Never), |
305 } | 305 } |
306 | 306 |
307 const SYSTEMD_PREFIX: &str = "systemd://"; | 307 const SYSTEMD_PREFIX: &str = "systemd://"; |
308 | 308 |
309 impl<I: Into<std::net::IpAddr>> From<(I, u16)> for SocketAddr { | |
310 fn from(value: (I, u16)) -> Self { | |
311 SocketAddr(SocketAddrInner::Ordinary(value.into())) | |
312 } | |
313 } | |
314 | |
315 impl From<std::net::SocketAddrV4> for SocketAddr { | |
316 fn from(value: std::net::SocketAddrV4) -> Self { | |
317 SocketAddr(SocketAddrInner::Ordinary(value.into())) | |
318 } | |
319 } | |
320 | |
321 impl From<std::net::SocketAddrV6> for SocketAddr { | |
322 fn from(value: std::net::SocketAddrV6) -> Self { | |
323 SocketAddr(SocketAddrInner::Ordinary(value.into())) | |
324 } | |
325 } | |
326 | |
309 impl std::str::FromStr for SocketAddr { | 327 impl std::str::FromStr for SocketAddr { |
310 type Err = ParseError; | 328 type Err = ParseError; |
311 | 329 |
312 fn from_str(s: &str) -> Result<Self, Self::Err> { | 330 fn from_str(s: &str) -> Result<Self, Self::Err> { |
313 SocketAddr::try_from_generic(s) | 331 SocketAddr::try_from_generic(s) |