aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2018-09-10 00:45:53 +0200
committerDaniel <kingdread@gmx.de>2018-09-10 00:45:53 +0200
commite16d9873db70d29d409ae989c9b18f28f1652434 (patch)
tree6a9200d96e99fb355e7a3fd7c4bd0ee8cbee60ed /src/main.rs
parent2c1203f6f2c3e6bbaf527fa202425ed465e89d69 (diff)
downloadraidgrep-e16d9873db70d29d409ae989c9b18f28f1652434.tar.gz
raidgrep-e16d9873db70d29d409ae989c9b18f28f1652434.tar.bz2
raidgrep-e16d9873db70d29d409ae989c9b18f28f1652434.zip
use unwrap! instead of if let
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs
index 2e3007c..85018c8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,6 +29,16 @@ mod output;
mod filters;
+macro_rules! unwrap {
+ ($p:pat = $e:expr => { $r:expr} ) => {
+ if let $p = $e {
+ $r
+ } else {
+ panic!("Pattern match failed!");
+ }
+ };
+}
+
/// A program that allows you to search through all your evtc logs for specific
/// people.
#[derive(StructOpt, Debug)]
@@ -230,25 +240,20 @@ fn extract_info(entry: &DirEntry, log: &Log) -> LogResult {
let mut players = log
.players()
.map(|p| {
- if let AgentKind::Player { profession, elite } = p.kind() {
- if let AgentName::Player {
- account_name,
- character_name,
- subgroup,
- } = p.name()
- {
- Player {
- account_name: account_name.clone(),
- character_name: character_name.clone(),
- profession: get_profession_name(*profession, *elite).into(),
- subgroup: *subgroup,
- }
- } else {
- unreachable!()
+ unwrap! { AgentKind::Player { profession, elite } = p.kind() => {
+ unwrap! { AgentName::Player {
+ account_name,
+ character_name,
+ subgroup,
+ } = p.name() =>
+ {
+ Player {
+ account_name: account_name.clone(),
+ character_name: character_name.clone(),
+ profession: get_profession_name(*profession, *elite).into(),
+ subgroup: *subgroup,
}
- } else {
- unreachable!()
- }
+ }}}}
}).collect::<Vec<Player>>();
players.sort_by_key(|p| p.subgroup);