From 10214e0295d72c88cd61085da67b9fc0f01e9728 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 3 Oct 2019 22:31:09 +0300 Subject: Change: add_step can't fail, don't return Result --- src/map.rs | 25 +++++++++++++------------ src/parser.rs | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/map.rs b/src/map.rs index a89f4fc..f442ecb 100644 --- a/src/map.rs +++ b/src/map.rs @@ -4,9 +4,10 @@ pub use crate::from_yaml; pub use crate::Status; pub use crate::Step; -/// Represent a full project roadmap. This stores all the steps needed -/// to reach the end goal. See the crate leve documentation for an -/// example. +/// Represent a full project roadmap. +/// +/// This stores all the steps needed to reach the end goal. See the +/// crate leve documentation for an example. #[derive(Clone,Debug)] pub struct Roadmap { steps: Vec, @@ -14,6 +15,8 @@ pub struct Roadmap { impl Roadmap { /// Create a new, empty roadmap. + /// + /// You probably want the `from_yaml` function instead. pub fn new() -> Roadmap { Roadmap { steps: vec![] } } @@ -26,7 +29,7 @@ impl Roadmap { .count() } - /// Return list of step names. + /// Iterate over step names. pub fn step_names(&self) -> impl Iterator { self.steps.iter().map(|step| step.name()) } @@ -36,11 +39,9 @@ impl Roadmap { self.steps.iter().filter(|step| step.name() == name).next() } - /// Add a step to the roadmap. This may fail, if there's a step - /// with that name already. - pub fn add_step(&mut self, step: &Step) -> Result<(), Box> { + /// Add a step to the roadmap. + pub fn add_step(&mut self, step: &Step) { self.steps.push(step.clone()); - Ok(()) } // Get iterator over refs to steps. @@ -190,7 +191,7 @@ mod tests { fn add_step_to_roadmap() { let mut roadmap = Roadmap::new(); let first = Step::new("first", "the first step"); - roadmap.add_step(&first).unwrap(); + roadmap.add_step(&first); let names: Vec<&str> = roadmap.step_names().collect(); assert_eq!(names, vec!["first"]); } @@ -199,7 +200,7 @@ mod tests { fn get_step_from_roadmap() { let mut roadmap = Roadmap::new(); let first = Step::new("first", "the first step"); - roadmap.add_step(&first).unwrap(); + roadmap.add_step(&first); let gotit = roadmap.get_step("first").unwrap(); assert_eq!(gotit.name(), "first"); assert_eq!(gotit.label(), "the first step"); @@ -258,8 +259,8 @@ blocked: let mut second = Step::new("second", ""); second.add_dependency("first"); second.set_status(Status::Goal); - roadmap.add_step(&first).unwrap(); - roadmap.add_step(&second).unwrap(); + roadmap.add_step(&first); + roadmap.add_step(&second); assert_eq!( roadmap.as_dot(999).unwrap(), "digraph \"roadmap\" { diff --git a/src/parser.rs b/src/parser.rs index 637220c..ac917eb 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -17,7 +17,7 @@ pub fn from_yaml(yaml: &str) -> Result> { for (name, value) in map { let step = step_from_value(&name, &value)?; - roadmap.add_step(&step)?; + roadmap.add_step(&step); } validate(&roadmap)?; -- cgit v1.2.1