prefer if let when possible
This commit is contained in:
parent
25d247f299
commit
c69cc61114
17
src/lib.rs
17
src/lib.rs
@ -26,15 +26,10 @@ use std::sync::Arc;
|
|||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::cell::{Cell, RefCell};
|
|
||||||
|
|
||||||
use transformable_channels::mpsc::TransformableSender;
|
use transformable_channels::mpsc::TransformableSender;
|
||||||
|
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use std::collections::btree_set::BTreeSet;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
@ -105,16 +100,14 @@ impl Tenquestionmarks {
|
|||||||
let arc_envelope = Arc::new(envelope);
|
let arc_envelope = Arc::new(envelope);
|
||||||
for (key, sender) in &module_senders {
|
for (key, sender) in &module_senders {
|
||||||
let from_this = String::from(*key);
|
let from_this = String::from(*key);
|
||||||
match self.subscriptions.get::<String>(&from_this) {
|
if let Some(subscription) = self.subscriptions.get::<String>(&from_this) {
|
||||||
Some(subscription) => {
|
|
||||||
if subscription.can_handle_event(&arc_envelope) {
|
if subscription.can_handle_event(&arc_envelope) {
|
||||||
match sender.send(arc_envelope.clone()) {
|
if let Err(err) = sender.send(arc_envelope.clone()) {
|
||||||
Err(err) => debug!("Failed to dispatch event to module \"{}\": {:?}", key, err),
|
debug!("Failed to dispatch event to module \"{}\": {:?}", key, err);
|
||||||
Ok(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
} else {
|
||||||
None => debug!("Failed to dispatch event to module \"{}\": No such module found!", key)
|
debug!("Failed to dispatch event to module \"{}\": No such module found!", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
23
src/main.rs
23
src/main.rs
@ -32,14 +32,13 @@ fn main () {
|
|||||||
init_logger();
|
init_logger();
|
||||||
|
|
||||||
let config_file_name = env::args().nth(1).unwrap_or("tenquestionmarks.toml".into());
|
let config_file_name = env::args().nth(1).unwrap_or("tenquestionmarks.toml".into());
|
||||||
match File::open(&config_file_name) {
|
if let Ok(mut file) = File::open(&config_file_name) {
|
||||||
Ok(mut file) => {
|
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
match file.read_to_string(&mut contents) {
|
if let Err(e) = file.read_to_string(&mut contents) {
|
||||||
Ok(_) => {
|
error!("Failed to open config file {}: {:?}", config_file_name, e);
|
||||||
|
} else {
|
||||||
let mut parser = Parser::new(&contents);
|
let mut parser = Parser::new(&contents);
|
||||||
match parser.parse() {
|
if let Some(configuration) = parser.parse() {
|
||||||
Some(configuration) => {
|
|
||||||
info!("Loaded configuration from: {}", config_file_name);
|
info!("Loaded configuration from: {}", config_file_name);
|
||||||
match Tenquestionmarks::from_configuration(configuration) {
|
match Tenquestionmarks::from_configuration(configuration) {
|
||||||
Ok(tqm) => {
|
Ok(tqm) => {
|
||||||
@ -48,19 +47,11 @@ fn main () {
|
|||||||
},
|
},
|
||||||
Err(e) => error!("Failed to initialize tenquestionmarks: {:?}", e)
|
Err(e) => error!("Failed to initialize tenquestionmarks: {:?}", e)
|
||||||
}
|
}
|
||||||
},
|
} else {
|
||||||
None => {
|
|
||||||
error!("Failed to parse config file {}: {:?}. Config file must be a valid TOML file.", config_file_name, parser.errors);
|
error!("Failed to parse config file {}: {:?}. Config file must be a valid TOML file.", config_file_name, parser.errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
} else {
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to open config file {}: {:?}", config_file_name, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
error!("Failed to open config file! Please specify path to a config file.");
|
error!("Failed to open config file! Please specify path to a config file.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -147,9 +147,8 @@ impl EventLoop for DiscordModule {
|
|||||||
channel: discord.get_channel(message.channel_id).ok().and_then(|channel| make_channel_object(discord.clone(), channel))
|
channel: discord.get_channel(message.channel_id).ok().and_then(|channel| make_channel_object(discord.clone(), channel))
|
||||||
};
|
};
|
||||||
|
|
||||||
match sender.send(Envelope::new(event::Event::Message { message: message })) {
|
if let Err(err) = sender.send(Envelope::new(event::Event::Message { message: message })) {
|
||||||
Err(err) => error!("Error sending message event: {:?}", err),
|
error!("Error sending message event: {:?}", err)
|
||||||
Ok(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
@ -85,4 +85,4 @@ end
|
|||||||
[autolink]
|
[autolink]
|
||||||
|
|
||||||
[logger]
|
[logger]
|
||||||
filters = [{ username = "Dave" }]
|
filters = [{ username = "Dave" }, { username = "Kevin" }]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user