You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@yoshuawuyts This code is worked.
And it is also my current solution, but I want to make my code look more neat and elegant.
So implement the trait ToSocketAddrs is probably the best solution.
pubstructDomainName(pubString,pubu16);
...// implement Deserialize for DomainName
...
#[derive(Deserialize)]pubenumAddress{/// IP AddressSocketAddr(SocketAddr),/// Domain name address, eg. example.com:8080Domain(DomainName),}#[derive(Deserialize)]pubstructConfig{pubaddr: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 ToSocketAddr for (String, u16).
Activity
yoshuawuyts commentedon Nov 19, 2019
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
ToSocketAddrs
is opaque, we could probably change it to be similar toFromStream::from_stream
without breaking anything.@bandheight out of curiosity: what's your use case for implementing
ToSocketAddrs
?ghost commentedon Nov 21, 2019
I'd be okay with changing the return type of
to_socket_addrs
toPin<Box<dyn Future>>
here. Performance impact of the change would be effectively none.honsunrise commentedon Nov 22, 2019
@yoshuawuyts I implemented an
enum
type to represent multiple address types.If this type implement the trait
ToSocketAddrs
, it will be passed directly toTcpListener::bind
and other similar functions.yoshuawuyts commentedon Nov 25, 2019
@bandheight does the following work for you?
If we don't already support
ToSocketAddr
for(String, u16)
then we should add that!honsunrise commentedon Nov 26, 2019
@yoshuawuyts This code is worked.
And it is also my current solution, but I want to make my code look more neat and elegant.
So implement the trait
ToSocketAddrs
is probably the best solution.I vote for it that support
ToSocketAddr
for(String, u16)
.dizda commentedon Jan 17, 2020
agreed with @bandheight, that'd be cleaner to implement ToSocketAddrs.
cf. use case:
👍
dizda commentedon Jan 17, 2020
Shadowsocks does it for a similar purpose, but with std::net::ToSocketAddrs.
cf. https://github.com/shadowsocks/shadowsocks-rust/blob/f4feba9fc1c8a968d90a592c5f4e86ffc6dd322b/src/relay/socks5.rs#L332