refactor with iter and filter
This commit is contained in:
parent
fbea2a40c3
commit
8cc5880135
@ -55,32 +55,24 @@ pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
|||||||
let scores_read = scores.read().expect("Should be able to read scores");
|
let scores_read = scores.read().expect("Should be able to read scores");
|
||||||
let scores_read_vec: Vec<Box<dyn Score<T>>> =
|
let scores_read_vec: Vec<Box<dyn Score<T>>> =
|
||||||
scores_read.iter().map(|s| s.clone_box()).collect();
|
scores_read.iter().map(|s| s.clone_box()).collect();
|
||||||
|
let filtered: Vec<&Box<dyn Score<T>>> = scores_read_vec
|
||||||
|
.iter()
|
||||||
|
.filter(|s| s.name().contains(&args.run))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if filtered.len() == 0 {
|
||||||
|
return Err("No score containing query found".into());
|
||||||
|
}
|
||||||
|
|
||||||
if args.all {
|
if args.all {
|
||||||
for s in scores_read_vec {
|
for s in filtered {
|
||||||
if s.name().contains(&args.run) {
|
println!("Running: {}", s.clone_box().name());
|
||||||
println!("Running: {}", s.clone_box().name());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut count = 0;
|
let score = filtered.get(args.number as usize);
|
||||||
let mut found = false;
|
match score {
|
||||||
for s in scores_read_vec {
|
Some(s) => println!("Running: {}", s.clone_box().name()),
|
||||||
if s.name().contains(&args.run) {
|
None => return Err("Invalid index given".into()),
|
||||||
found = true;
|
|
||||||
if count < args.number {
|
|
||||||
// Skip scores that aren't the nth specified
|
|
||||||
count = count + 1;
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
// Run nth score found
|
|
||||||
println!("Running: {}", s.clone_box().name());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
println!("Couldn't find score by that name")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user