-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To implement ToSocketAddrs for a custom type the ToSocketAddrsFuture should be pub use #539
Comments
Ref https://docs.rs/async-std/1.0.1/async_std/net/trait.ToSocketAddrs.html. From a glance it seems this is indeed accurate. Since the result type from @bandheight out of curiosity: what's your use case for implementing |
I'd be okay with changing the return type of |
@yoshuawuyts I implemented an pub enum Address {
/// IP Address
SocketAddr(SocketAddr),
/// Domain name address, eg. example.com:8080
Domain(String, u16),
} If this type implement the trait |
@bandheight does the following work for you? async fn bind_socket(addr: Address) -> io::Result<TcpListener> {
match addr {
SocketAddr(addr) => TcpListener::bind(addr).await?,
SocketAddr((addr, port) => TcpListener::bind((&*addr, port)).await?,
}
} If we don't already support |
@yoshuawuyts This code is worked. pub struct DomainName(pub String, pub u16);
...
// implement Deserialize for DomainName
...
#[derive(Deserialize)]
pub enum Address {
/// IP Address
SocketAddr(SocketAddr),
/// Domain name address, eg. example.com:8080
Domain(DomainName),
}
#[derive(Deserialize)]
pub struct Config {
pub addr: Address,
}
...
let config: Config = <deserialize from config file>;
...
// This is neat and elegant.
let listener = TcpListener::bind(config.addr); I vote for it that support |
agreed with @bandheight, that'd be cleaner to implement ToSocketAddrs. cf. use case:
👍 |
Shadowsocks does it for a similar purpose, but with std::net::ToSocketAddrs. |
No description provided.
The text was updated successfully, but these errors were encountered: