Added simple example, and changed how IrcServer creation works.
This commit is contained in:
parent
42b4dcbf03
commit
c20038951e
2 changed files with 37 additions and 7 deletions
26
examples/simple.rs
Normal file
26
examples/simple.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#![feature(slicing_syntax)]
|
||||
extern crate irc;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use irc::data::config::Config;
|
||||
use irc::server::{IrcServer, Server};
|
||||
use irc::server::utils::identify;
|
||||
|
||||
fn main() {
|
||||
let config = Config {
|
||||
owners: vec!("awe".into_string()),
|
||||
nickname: "pickles".into_string(),
|
||||
username: "pickles".into_string(),
|
||||
realname: "pickles".into_string(),
|
||||
password: "".into_string(),
|
||||
server: "irc.fyrechat.net".into_string(),
|
||||
port: 6667,
|
||||
channels: vec!("#vana".into_string()),
|
||||
options: HashMap::new(),
|
||||
};
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
identify(&server).unwrap();
|
||||
for message in server.iter() {
|
||||
println!("RCV: {}", message);
|
||||
}
|
||||
}
|
|
@ -30,15 +30,19 @@ pub struct IrcServer<'a, T, U> where T: IrcWriter, U: IrcReader {
|
|||
}
|
||||
|
||||
impl<'a> IrcServer<'a, BufferedWriter<TcpStream>, BufferedReader<TcpStream>> {
|
||||
/// Creates a new IRC Server connection from the specified configuration, connecting immediately.
|
||||
/// Creates a new IRC Server connection from the configuration at the specified path, connecting immediately.
|
||||
#[experimental]
|
||||
pub fn new(config: &str) -> IoResult<IrcServer<'a, BufferedWriter<TcpStream>, BufferedReader<TcpStream>>> {
|
||||
let config = try!(Config::load_utf8(config));
|
||||
let conn = try!(Connection::connect(config.server[], config.port));
|
||||
Ok(IrcServer {
|
||||
conn: conn,
|
||||
config: config
|
||||
})
|
||||
IrcServer::from_connection(config, conn)
|
||||
}
|
||||
|
||||
/// Creates a new IRC server connection from the specified configuration, connecting immediately.
|
||||
#[experimental]
|
||||
pub fn from_config(config: Config) -> IoResult<IrcServer<'a, BufferedWriter<TcpStream>, BufferedReader<TcpStream>>> {
|
||||
let conn = try!(Connection::connect(config.server[], config.port));
|
||||
IrcServer::from_connection(config, conn)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,10 +63,10 @@ impl<'a, T, U> Server<'a, T, U> for IrcServer<'a, T, U> where T: IrcWriter, U: I
|
|||
impl<'a, T, U> IrcServer<'a, T, U> where T: IrcWriter, U: IrcReader {
|
||||
/// Creates an IRC server from the specified configuration, and any arbitrary Connection
|
||||
#[experimental]
|
||||
pub fn from_connection(config: &str, conn: Connection<T, U>) -> IoResult<IrcServer<'a, T, U>> {
|
||||
pub fn from_connection(config: Config, conn: Connection<T, U>) -> IoResult<IrcServer<'a, T, U>> {
|
||||
Ok(IrcServer {
|
||||
conn: conn,
|
||||
config: try!(Config::load_utf8(config))
|
||||
config: config
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue