summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Krehl <mario-krehl@gmx.de>2017-12-10 14:59:38 +0100
committerMario Krehl <mario-krehl@gmx.de>2017-12-10 14:59:38 +0100
commit4b57b7f93737fe1ebbfaa6ab20731b4220a8222d (patch)
treebc1d432d7335225bcaf7ea788b5b3f07a5032cd1
parent0b7f6cd62bd821b96cc9c7bf53e08da7db7b7835 (diff)
Add functionality to parse the requires targets into a HashMap for later use
-rw-r--r--src/main.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index c784d7c..f0cac8f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,7 @@ extern crate serde_derive;
extern crate serde_json;
extern crate simplelog;
+use std::collections::HashMap;
use std::process::exit;
use std::fs::File;
@@ -57,18 +58,26 @@ fn query(data: Json<Query>, config: State<Config>) -> Result<Json<QueryResponse>
let targets = data.0.targets;
debug!("targets: {:?}", targets);
let response : Vec<TargetData> = Vec::new();
- let target_collection : Vec<(LogItem, Vec<String>)> = Vec::new();
- let mut target_hash : std::collections::HashMap<&String, (&LogItem, &Vec<String>)> = std::collections::HashMap::new();
+ let mut target_hash : HashMap<&String, (&LogItem, Vec<String>)> = HashMap::new();
for li in config.items() {
for t in targets.clone() {
if li.aliases().contains(&t.target) {
- if let Some(&(_, ref mut cnames)) = target_hash.get(&li.alias()) {
- cnames.push(t.target.split('.').nth(1).ok_or(Error::from("no capture name found"))?.into());
+ if target_hash.contains_key(&li.alias()) {
+ if let Some(&mut (litem, ref mut cnames)) = target_hash.get_mut(&li.alias()) {
+ cnames.push(t.target.split('.').nth(1).ok_or(Error::from("no capture name found"))?.into());
+ }
}
else {
target_hash.insert(
li.alias(),
- (&li, &vec![t.target.split('.').nth(1).ok_or(Error::from("no capture name found"))?.into()])
+ (&li, vec![
+ t.target
+ .split('.')
+ .nth(1)
+ .ok_or(Error::from("no capture name found"))?
+ .into()
+ ]
+ )
);
}
}