Skip to content

Commit afa3819

Browse files
committed
Added From<(IpAddr, u16)> for Socket<'static>
Signed-off-by: Jiahao XU <[email protected]>
1 parent 3ec732d commit afa3819

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/changelog.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::*;
99
/// - `From<&'a Path> for Socket<'a>`
1010
/// - `From<PathBuf> for Socket<'a>`
1111
/// - `From<Box<Path>> for Socket<'a>`
12+
/// - `From<(IpAddr, u16)> for Socket<'static>`
1213
///
1314
/// ## Changed
1415
/// - [`Session::request_port_forward`] now takes `impl Into<...>`

src/port_forwarding.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::ffi::OsStr;
77
use std::borrow::Cow;
88
use std::fmt;
99
use std::io;
10-
use std::net::{SocketAddr, ToSocketAddrs};
10+
use std::net::{self, SocketAddr, ToSocketAddrs};
1111
use std::path::{Path, PathBuf};
1212

1313
/// Type of forwarding
@@ -52,6 +52,19 @@ impl From<SocketAddr> for Socket<'static> {
5252
Socket::TcpSocket(addr)
5353
}
5454
}
55+
56+
macro_rules! impl_from_addr {
57+
($ip:ty) => {
58+
impl From<($ip, u16)> for Socket<'static> {
59+
fn from(addr: ($ip, u16)) -> Self {
60+
Socket::new(&addr).unwrap()
61+
}
62+
}
63+
};
64+
}
65+
66+
impl_from_addr!(net::IpAddr);
67+
5568
impl<'a> From<Cow<'a, Path>> for Socket<'a> {
5669
fn from(path: Cow<'a, Path>) -> Self {
5770
Socket::UnixSocket { path }

0 commit comments

Comments
 (0)