Added for_each_incoming helper to Server.
This commit is contained in:
parent
f0e49d403f
commit
8c9a1aca2c
4 changed files with 23 additions and 12 deletions
10
README.md
10
README.md
|
@ -31,10 +31,9 @@ fn main() {
|
|||
};
|
||||
let server = IrcServer::from_config(cfg).unwrap();
|
||||
server.identify().unwrap();
|
||||
server.stream().for_each(|message| {
|
||||
server.for_each_incoming(|message| {
|
||||
// Do message processing.
|
||||
Ok(())
|
||||
}).wait().unwrap()
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -55,10 +54,9 @@ use irc::client::prelude::*;
|
|||
fn main() {
|
||||
let server = IrcServer::new("config.json").unwrap();
|
||||
server.identify().unwrap();
|
||||
server.stream().for_each(|message| {
|
||||
server.for_each_incoming(|message| {
|
||||
// Do message processing.
|
||||
Ok(())
|
||||
}).wait().unwrap()
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -11,9 +11,11 @@ fn main() {
|
|||
channels: Some(vec!["#irc-crate".to_owned()]),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
server.identify().unwrap();
|
||||
server.stream().for_each(|message| {
|
||||
|
||||
server.for_each_incoming(|message| {
|
||||
print!("{}", message);
|
||||
match message.command {
|
||||
Command::PRIVMSG(ref target, ref msg) => {
|
||||
|
@ -23,6 +25,5 @@ fn main() {
|
|||
}
|
||||
_ => (),
|
||||
}
|
||||
Ok(())
|
||||
}).wait().unwrap()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -12,9 +12,11 @@ fn main() {
|
|||
use_ssl: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
server.identify().unwrap();
|
||||
server.stream().for_each(|message| {
|
||||
|
||||
server.for_each_incoming(|message| {
|
||||
print!("{}", message);
|
||||
match message.command {
|
||||
Command::PRIVMSG(ref target, ref msg) => {
|
||||
|
@ -24,6 +26,5 @@ fn main() {
|
|||
}
|
||||
_ => (),
|
||||
}
|
||||
Ok(())
|
||||
}).wait().unwrap()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -33,6 +33,17 @@ pub trait Server {
|
|||
/// Gets a stream of incoming messages from the Server.
|
||||
fn stream(&self) -> ServerStream;
|
||||
|
||||
/// Blocks on the stream, running the given function on each incoming message as they arrive.
|
||||
fn for_each_incoming<F>(&self, mut f: F) -> ()
|
||||
where
|
||||
F: FnMut(Message) -> (),
|
||||
{
|
||||
self.stream().for_each(|msg| {
|
||||
f(msg);
|
||||
Ok(())
|
||||
}).wait().unwrap()
|
||||
}
|
||||
|
||||
/// Gets a list of currently joined channels. This will be none if tracking is not supported
|
||||
/// altogether (such as when the `nochanlists` feature is enabled).
|
||||
fn list_channels(&self) -> Option<Vec<String>>;
|
||||
|
|
Loading…
Add table
Reference in a new issue