diff --git a/hptp-recv/src/main.rs b/hptp-recv/src/main.rs index 2cd28ba..1d2e115 100644 --- a/hptp-recv/src/main.rs +++ b/hptp-recv/src/main.rs @@ -1,41 +1,5 @@ -use std::str::FromStr; - extern crate hptp; -#[derive(Debug)] -struct Hostname { - ip: String, - port: u16, -} - -struct InvalidHostnameError; - -impl FromStr for Hostname { - type Err = InvalidHostnameError; - fn from_str(s: &str) -> Result { - let i = s.find(':').ok_or(InvalidHostnameError)?; - Ok(Hostname { - ip: s[..i].into(), - port: s[i + 1..].parse().map_err(|_| InvalidHostnameError)?, - }) - } -} - -fn usage() { - print!("usage:\n./3700recv :\n") -} - -fn parse_args() -> Result { - std::env::args().nth(1).ok_or(())?.parse().map_err(|_| ()) -} - fn main() { - match parse_args() { - Ok(x) => start(x), - Err(_) => usage(), - } -} - -fn start(hn: Hostname) { - println!("ip={}, port={}", hn.ip, hn.port) + println!("{}", hptp::RECV_GREETING); } diff --git a/hptp-send/src/main.rs b/hptp-send/src/main.rs index c6d4d76..d200e36 100644 --- a/hptp-send/src/main.rs +++ b/hptp-send/src/main.rs @@ -1,5 +1,41 @@ +use std::str::FromStr; + extern crate hptp; -fn main() { - println!("{}", hptp::SEND_GREETING); +#[derive(Debug)] +struct Hostname { + ip: String, + port: u16, +} + +struct InvalidHostnameError; + +impl FromStr for Hostname { + type Err = InvalidHostnameError; + fn from_str(s: &str) -> Result { + let i = s.find(':').ok_or(InvalidHostnameError)?; + Ok(Hostname { + ip: s[..i].into(), + port: s[i + 1..].parse().map_err(|_| InvalidHostnameError)?, + }) + } +} + +fn usage() { + print!("usage:\n./3700send :\n") +} + +fn parse_args() -> Result { + std::env::args().nth(1).ok_or(())?.parse().map_err(|_| ()) +} + +fn main() { + match parse_args() { + Ok(x) => start(x), + Err(_) => usage(), + } +} + +fn start(hn: Hostname) { + println!("ip={}, port={}", hn.ip, hn.port) }