Added identify(...) utility, and clarified intent in some places using match.
This commit is contained in:
parent
4d7c2065e9
commit
42b4dcbf03
3 changed files with 21 additions and 7 deletions
|
@ -70,11 +70,12 @@ impl FromStr for Message {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
let command = if let Some(cmd) = state.find(' ').map(|i| s[..i]) {
|
||||
let command = match state.find(' ').map(|i| s[..i]) {
|
||||
Some(cmd) => {
|
||||
state = state.find(' ').map_or("", |i| s[i..]);
|
||||
cmd
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
_ => return None
|
||||
};
|
||||
let args: Vec<_> = state.splitn(14, ' ').collect();
|
||||
Some(Message::new(prefix, command, if args.len() > 0 { Some(args) } else { None }, suffix))
|
||||
|
|
|
@ -86,7 +86,9 @@ impl<'a, T, U> ServerIterator<'a, T, U> where T: IrcWriter, U: IrcReader {
|
|||
impl<'a, T, U> Iterator<Message> for ServerIterator<'a, T, U> where T: IrcWriter, U: IrcReader {
|
||||
fn next(&mut self) -> Option<Message> {
|
||||
let line = self.server.conn.recv();
|
||||
if let Err(_) = line { return None }
|
||||
from_str(line.unwrap()[])
|
||||
match line {
|
||||
Err(_) => None,
|
||||
Ok(msg) => from_str(msg[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,13 @@
|
|||
//! Utilities and shortcuts for working with IRC servers
|
||||
#![experimental]
|
||||
|
||||
use std::io::IoResult;
|
||||
use data::command::{NICK, USER};
|
||||
use data::kinds::{IrcReader, IrcWriter};
|
||||
use server::Server;
|
||||
|
||||
/// Sends a NICK and USER to identify
|
||||
pub fn identify<'a, T, U>(server: &Server<'a, T, U>) -> IoResult<()> where T: IrcWriter, U: IrcReader {
|
||||
try!(server.send(NICK(server.config().nickname[])));
|
||||
server.send(USER(server.config().username[], "0", server.config().realname[]))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue