summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-10-03 22:31:09 +0300
committerLars Wirzenius <liw@liw.fi>2019-10-03 22:31:09 +0300
commit10214e0295d72c88cd61085da67b9fc0f01e9728 (patch)
tree4ee77d302d568147ea4b9321472d12ba820c5776
parentacbdce9918d7f7c0443fd6857b79b2737d1ce9ed (diff)
downloadroadmap-10214e0295d72c88cd61085da67b9fc0f01e9728.tar.gz
Change: add_step can't fail, don't return Result
-rw-r--r--src/map.rs25
-rw-r--r--src/parser.rs2
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<Step>,
@@ -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<Item=&str> {
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<dyn std::error::Error>> {
+ /// 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<Roadmap, Box<dyn Error>> {
for (name, value) in map {
let step = step_from_value(&name, &value)?;
- roadmap.add_step(&step)?;
+ roadmap.add_step(&step);
}
validate(&roadmap)?;