From 03eff314a7758a89f781aa2f681613c78d50dcb1 Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Sat, 7 Mar 2020 15:40:35 -0500 Subject: [PATCH] i got send/recv mixed up --- hptp-recv/src/main.rs | 38 +------------------------------------- hptp-send/src/main.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 39 deletions(-) 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) }