Re:Announcing Tokio 0.1
by koolba on Wednesday January 11, 2017 @01:43PM
(#13376338)
Where is string to address parse implementation defined? I took a peek at SocketAddr and see a from_str function. Does that name have special significance?
[ Parent
| on HN ]
The method `from_str` is from the FromStr trait. [1] The `parse` function only works on types that implement FromStr. It's "special" in that it's the conventional way to do things, but the compiler does not treat FromStr specially.
Re:Announcing Tokio 0.1
by steveklabnik on Wednesday January 11, 2017 @01:52PM
(#13376421)
It's at the very bottom of https://doc.rust-lang.org/std/net/enum.SocketAddr.html, the part that says
impl FromStr for SocketAddr
If you look at parse https://doc.rust-lang.org/std/primitive.str.html#method.pars... it says fn parse<F>(&self) -> Result<F, F::Err> where F: FromStr
So any type that implements FromStr can be parse'd from a &str.which has a link to the actual src which is here-ish and is what you might expect
https://doc.rust-lang.org/src/std/up/src/libstd/net/parser.r...
Re:Announcing Tokio 0.1
by winstonewert on Wednesday January 11, 2017 @01:53PM
(#13376428)
If you look closely, you'll see that the from_str function is part of the implementation of the FromStr trait for the SocketAddr struct. Its this FromStr trait that the parse() method depends on.