Created
June 7, 2014 22:39
-
-
Save thomaslee/f676c30489426a8abf51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait ToBindSocketAddr { | |
fn to_bind_socket_addr(self) -> IoResult<SocketAddr> | |
} | |
impl<'a> ToBindSocketAddr for &'a str { | |
fn to_bind_socket_addr(self) -> IoResult<SocketAddr> { | |
match FromStr::from_str(self) { | |
Some(addr) => Ok(addr), | |
None => { | |
Err(IoError{ | |
kind: InvalidInput, | |
desc: "error parsing bind address", | |
detail: None | |
}) | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let addr = "127.0.0.1:1234".to_bind_socket_addr() | |
/* | |
/home/tom/Source/rust/src/libstd/io/net/tcp.rs:1408:37: 1408:58 error: type `&'static str` does not implement any method in scope named `to_bind_socket_addr` | |
/home/tom/Source/rust/src/libstd/io/net/tcp.rs:1408 let addr = "127.0.0.1:1234".to_bind_socket_addr().unwrap(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment