summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-09-26 11:12:52 +0300
committerLars Wirzenius <liw@liw.fi>2019-09-26 11:12:52 +0300
commitfb06994741fb203d7a40b614132b0bddd50f1410 (patch)
treef1080f1a08fff1444271eeb13d37ce1ee10ebc24 /src
parent58011577ec6fdc8264659f2e3456ae6ff4b4f39f (diff)
downloadroadmap-fb06994741fb203d7a40b614132b0bddd50f1410.tar.gz
Change: simplify match arms
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 2ab1ecb..1fc6435 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,11 +32,11 @@
use serde_yaml;
use serde_yaml::Value;
use std::collections::HashMap;
-use textwrap::fill;
use std::error::Error;
+use textwrap::fill;
/// A step in a roadmap.
-#[derive(Clone,Debug,PartialEq)]
+#[derive(Clone, Debug, PartialEq)]
pub struct Step {
name: String,
status: String,
@@ -183,9 +183,11 @@ impl Roadmap {
match status {
"" | "goal" | "ready" | "finished" | "next" | "blocked" => (),
_ => {
- let msg = format!("step {:?} status {:?} is not allowed",
- step.name(), status);
- return Err(msg);
+ return Err(format!(
+ "step {:?} status {:?} is not allowed",
+ step.name(),
+ status
+ ))
}
}
}
@@ -195,9 +197,11 @@ impl Roadmap {
for depname in step.dependencies() {
match self.get_step(depname) {
None => {
- let msg = format!("step {} depends on missing {}",
- step.name(), depname);
- return Err(msg);
+ return Err(format!(
+ "step {} depends on missing {}",
+ step.name(),
+ depname
+ ))
}
Some(_) => (),
}
@@ -246,7 +250,9 @@ impl Roadmap {
/// Compute status of any step for which it has not been specified
/// in the input.
pub fn set_missing_statuses(&mut self) {
- let new_steps: Vec<Step> = self.steps.iter()
+ let new_steps: Vec<Step> = self
+ .steps
+ .iter()
.map(|step| {
let mut step = step.clone();
if self.is_unset(&step) {
@@ -276,13 +282,17 @@ impl Roadmap {
// Should unset status be ready? In other words, if there are any
// dependencies, they are all finished.
fn is_ready(&self, step: &Step) -> bool {
- self.dep_statuses(step).iter().all(|status| status == &"finished")
+ self.dep_statuses(step)
+ .iter()
+ .all(|status| status == &"finished")
}
// Should unset status be blocked? In other words, if there are
// any dependencies, that aren't finished.
fn is_blocked(&self, step: &Step) -> bool {
- self.dep_statuses(step).iter().any(|status| status != &"finished")
+ self.dep_statuses(step)
+ .iter()
+ .any(|status| status != &"finished")
}
// Return vector of all statuses of all dependencies
@@ -301,9 +311,7 @@ impl Roadmap {
// Should unset status be goal? In other words, does any other
// step depend on this one?
fn is_goal(&self, step: &Step) -> bool {
- let has_parent = self.steps
- .iter()
- .any(|other| other.depends_on(step.name()));
+ let has_parent = self.steps.iter().any(|other| other.depends_on(step.name()));
!has_parent
}
@@ -462,7 +470,8 @@ mod tests {
#[test]
fn set_missing_goal_status() {
- let mut r = Roadmap::from_yaml("
+ let mut r = Roadmap::from_yaml(
+ "
goal:
depends:
- finished
@@ -482,7 +491,9 @@ blocked:
depends:
- ready
- next
-").unwrap();
+",
+ )
+ .unwrap();
r.set_missing_statuses();
assert_eq!(r.get_step("goal").unwrap().status(), "goal");
assert_eq!(r.get_step("finished").unwrap().status(), "finished");