Create bin crate for testing
This commit is contained in:
parent
9f878dd578
commit
c665ae8efb
21
src/lib.rs
21
src/lib.rs
|
@ -1,8 +1,8 @@
|
|||
use std::net::TcpStream;
|
||||
use std::io::{Error, Read, Write};
|
||||
use std::time::Duration;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use std::io::{Error, Read, Write};
|
||||
use std::net::TcpStream;
|
||||
use std::time::Duration;
|
||||
|
||||
lazy_static! {
|
||||
static ref PING_RE: Regex = Regex::new(r"^PING\s*:").unwrap();
|
||||
|
@ -10,20 +10,19 @@ lazy_static! {
|
|||
|
||||
pub struct Client {
|
||||
stream: TcpStream,
|
||||
config: Config
|
||||
config: Config,
|
||||
}
|
||||
|
||||
pub struct Config {
|
||||
username: String,
|
||||
nickname: String,
|
||||
mode: String
|
||||
mode: String,
|
||||
}
|
||||
|
||||
pub enum Command {
|
||||
PING(String)
|
||||
PING(String),
|
||||
}
|
||||
|
||||
|
||||
impl Command {
|
||||
fn from_str(s: &str) -> Option<Self> {
|
||||
let new = s.trim();
|
||||
|
@ -50,8 +49,8 @@ impl Client {
|
|||
let mut buffer = [0u8; 512];
|
||||
|
||||
match self.stream.read(&mut buffer) {
|
||||
Ok(_) => {},
|
||||
Err(_) => return None
|
||||
Ok(_) => {}
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
Some(String::from_utf8_lossy(&buffer).into())
|
||||
|
@ -78,7 +77,7 @@ impl Config {
|
|||
Self {
|
||||
username: username.into(),
|
||||
nickname: nickname.unwrap_or(username).into(),
|
||||
mode: mode.unwrap_or("").into()
|
||||
mode: mode.unwrap_or("").into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/main.rs
Normal file
22
src/main.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use irsc::{Client, Config};
|
||||
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! loop_n {
|
||||
($n:expr, $c:expr) => {{
|
||||
for _ in 0..$n {
|
||||
$c
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let config = Config::new("test", None, Some("+B"));
|
||||
let mut client =
|
||||
Client::new("192.168.1.28", 6667, config).expect("Unable to connect to IRC server");
|
||||
|
||||
loop {
|
||||
if let Some(line) = client.read_string() {
|
||||
print!("{}", line);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue