summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-09-18 11:04:21 +0300
committerLars Wirzenius <liw@liw.fi>2019-09-18 11:04:21 +0300
commit04bb757f41b7d468d783f6bb062e576dad54b60e (patch)
tree5bd2d5473d01dba9f320125a7a694d655ea43b8c /src
parentd4233ad52fa6591c0b0915faaf5eb971daba7748 (diff)
downloadroadmap-04bb757f41b7d468d783f6bb062e576dad54b60e.tar.gz
Add: some first doctest for Step
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 5e49da1..625bb90 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,23 @@
+//! Model project roadmaps and step dependencies
+//!
+//! This crate models a roadmap as steps, which may depend on each
+//! other, and a directed acyclic graph (DAG) of said steps, which
+//! leads to the end goal. There is no support for due dates,
+//! estimates, or other such management features. These roadmaps only
+//! care about what steps need to be take, in what order, to reach the
+//! goal.
+
+
+/// 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,
@@ -5,40 +25,53 @@ pub struct Step {
}
impl Step {
- pub fn new() -> Step {
+ /// Create a new step with a name and a label.
+ pub fn new(name: &str, label: &str) -> Step {
Step {
- name: "".to_string(),
- label: "".to_string(),
+ name: name.to_string(),
+ label: label.to_string(),
depends: vec![],
}
}
- pub fn name(self) -> String {
+ /// Return the name of a step.
+ pub fn name(&self) -> String {
self.name.to_string()
}
- pub fn label(self) -> String {
+ /// Return the label of a step.
+ pub fn label(&self) -> String {
self.label.to_string()
}
- pub fn depends(self) -> Vec<String> {
+ /// Return vector of names of dependencies for a step.
+ pub fn dependencies(self) -> Vec<String> {
self.depends.clone()
}
+
+ /// Add the name of a dependency to step.
+ pub fn add_dependency(mut self, name: &str) {
+ self.depends.push(name.to_string());
+ }
}
+/// All the steps to get to the end goal.
pub struct Roadmap {
steps: Vec<Step>,
}
impl Roadmap {
+ /// Create a new, empty roadmap.
pub fn new() -> Roadmap {
Roadmap { steps: vec![] }
}
+ /// Create a new roadmap from a YAML representation.
pub fn from_yaml(_yaml: String) -> Result<Roadmap, Box<dyn std::error::Error>> {
Ok(Roadmap::new())
}
+ /// Return list of step names.
pub fn steps(self) -> Vec<String> {
let mut names = vec![];
for step in self.steps {
@@ -47,10 +80,14 @@ impl Roadmap {
names
}
+ /// Get a step, given its name.
pub fn get_step(self, _name: &str) -> Option<Step> {
None
}
+ /// Get a Graphviz dot language representation of a roadmap. This
+ /// is the textual representation, and the caller needs to use the
+ /// Graphviz dot(1) tool to create an image from it.
pub fn as_dot(self) -> Result<String, Box<dyn std::error::Error>> {
Ok("".to_string())
}