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