From d085789fab2af19d932eb4a2b4aa1541437f7d79 Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Sun, 18 Mar 2018 22:03:50 +0100 Subject: [PATCH] webhook test for Discord (also still errors for macros) --- Lucien/Rust/src/client.rs | 46 +++++++++++++++++---------------------- Lucien/Rust/src/main.rs | 2 ++ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Lucien/Rust/src/client.rs b/Lucien/Rust/src/client.rs index 207865a..0a01301 100644 --- a/Lucien/Rust/src/client.rs +++ b/Lucien/Rust/src/client.rs @@ -1,20 +1,10 @@ +use std; use std::io::*; use std::net::TcpStream; use std::thread; static leave_msg: &str = "BYE"; -// macro_rules! send { -// ($line:expr) => ({ -// try!(writeln!(writer, "{}", $line)); -// try!(writer.flush()); -// }) -// } - -fn send(writer: BufWriter<&TcpStream>,text: &str) { - -} - fn get_entry() -> String { let mut buf = String::new(); @@ -23,19 +13,25 @@ fn get_entry() -> String { } fn write_to_server(stream: TcpStream) { - let mut writer = BufWriter::new(&stream); + macro_rules! send { + ($line:expr) => ({ + try!(writeln!(writer, "{}", $line)); + try!(writer.flush()); + }) + } + loop { match &*get_entry() { "/quit" => { println!("Disconnecting..."); - + send!("BYE"); println!("Disconnected!"); return (); } line => { - send(BufWriter::new(&stream), line); + send!(line); } } } @@ -56,14 +52,14 @@ fn exchange_with_server(stream: TcpStream) { match reader.read_line(&mut line) { Ok(len) => { if len == 0 { - // Reader is at EOF. - return Err(Error::new(ErrorKind::Other, "unexpected EOF")); + // Reader is at EOF. Could use ErrorKind::UnexpectedEOF, but still unstable. + let ret = std::io::Error::new(std::io::ErrorKind::Other, "test"); + return Err(ret): std::result::Result<&str, std::io::Error>; + // return Err(Error::new(ErrorKind::Other, "unexpected EOF")); } line.pop(); } - Err(e) => { - return Err(e); - } + Err(e) => { return Err(e); } }; line }) @@ -73,13 +69,11 @@ fn exchange_with_server(stream: TcpStream) { write_to_server(stream.try_clone().unwrap()); }); - match(|| { - loop { - let input = receive!(); - println!("{}", input); - } - - })() { + match (|| loop { + let input = receive!(); + println!("{}", input); + })() + { Ok(_) => { println!("Left?"); } diff --git a/Lucien/Rust/src/main.rs b/Lucien/Rust/src/main.rs index 7aa08a4..0b90c76 100644 --- a/Lucien/Rust/src/main.rs +++ b/Lucien/Rust/src/main.rs @@ -1,3 +1,5 @@ +#![feature(type_ascription)] + use std::env; pub mod client;