summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-09-19 08:07:07 +0300
committerLars Wirzenius <liw@liw.fi>2019-09-19 08:07:07 +0300
commitc8d1010a0ac8288a5bd11d02843d18092257af51 (patch)
treeb9802a4011202d087397b0a052a604c0d536df63 /src
parentedf0551ef8d60c72aa4669ae2f6ea4d90b8d85cb (diff)
downloadroadmap-c8d1010a0ac8288a5bd11d02843d18092257af51.tar.gz
Add: example to crate doc
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c6256ae..d0f06df 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,17 +6,28 @@
//! estimates, or other such management features. These roadmaps only
//! care about what steps need to be take, in what order, to reach the
//! goal.
+//!
+//! # Example
+//! ```
+//! # use roadmap::Step;
+//! # fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
+//! let mut r = roadmap::Roadmap::new();
+//! assert_eq!(r.steps().len(), 0);
+//!
+//! let endgoal = roadmap::Step::new("endgoal", "the end goal");
+//! assert_eq!(endgoal.name(), "endgoal".to_string());
+//! assert_eq!(endgoal.label(), "the end goal".to_string());
+//! r.add_step(endgoal)?;
+//! assert_eq!(r.steps().len(), 1);
+//!
+//! let first = roadmap::Step::new("first", "the first step");
+//! r.add_step(first)?;
+//! assert_eq!(r.steps().len(), 2);
+//! # Ok(())
+//! # }
+//! ```
/// A step in a roadmap.
-///
-/// # Example
-///
-/// ```
-/// # use roadmap::Step;
-/// let s = Step::new("foo", "make foo happen");
-/// assert_eq!(s.name(), "foo".to_string());
-/// assert_eq!(s.label(), "make foo happen".to_string());
-/// ```
pub struct Step {
name: String,
label: String,
@@ -71,9 +82,9 @@ impl Roadmap {
}
/// Return list of step names.
- pub fn steps(self) -> Vec<String> {
+ pub fn steps(&self) -> Vec<String> {
let mut names = vec![];
- for step in self.steps {
+ for step in self.steps.iter() {
names.push(step.name());
}
names
@@ -86,7 +97,7 @@ impl Roadmap {
/// 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>> {
+ pub fn add_step(&mut self, step: Step) -> Result<(), Box<dyn std::error::Error>> {
self.steps.push(step);
Ok(())
}