diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-09-19 08:32:44 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-09-19 08:32:44 +0300 |
commit | 446e0f28bdd640f26def54ad069baa1c9cc9ec41 (patch) | |
tree | f92770600a4f9faf08f1619a60b4dfdc3e736a90 /src | |
parent | 5dd4de4ff1b19cffbedde49612268154758a144a (diff) | |
download | roadmap-446e0f28bdd640f26def54ad069baa1c9cc9ec41.tar.gz |
Change: avoid unnecessary copying of steps
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -17,17 +17,23 @@ //! let endgoal = roadmap::Step::new("endgoal", "the end goal"); //! assert_eq!(endgoal.name(), "endgoal"); //! assert_eq!(endgoal.label(), "the end goal"); -//! r.add_step(endgoal)?; +//! r.add_step(&endgoal)?; //! assert_eq!(r.steps().len(), 1); //! //! let first = roadmap::Step::new("first", "the first step"); -//! r.add_step(first)?; +//! r.add_step(&first)?; //! assert_eq!(r.steps().len(), 2); +//! +//! if let Some(step) = r.get_step("endgoal") { +//! step.add_dependency("first"); +//! assert_eq!(endgoal.dependencies(), vec!["first"]); +//! } //! # Ok(()) //! # } //! ``` /// A step in a roadmap. +#[derive(Clone)] pub struct Step { name: String, label: String, @@ -60,7 +66,7 @@ impl Step { } /// Add the name of a dependency to step. - pub fn add_dependency(mut self, name: &str) { + pub fn add_dependency(&mut self, name: &str) { self.depends.push(name.to_string()); } } @@ -91,14 +97,14 @@ impl Roadmap { } /// Get a step, given its name. - pub fn get_step<'a>(&'a self, _name: &str) -> Option<&'a Step> { + pub fn get_step<'a>(&'a self, _name: &str) -> Option<&'a mut Step> { None } /// 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>> { - self.steps.push(step); + pub fn add_step(&mut self, step: &Step) -> Result<(), Box<dyn std::error::Error>> { + self.steps.push(step.clone()); Ok(()) } |