diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-10-04 10:42:10 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-10-04 10:42:10 +0300 |
commit | d3a81e80937582f8eb5212296d68104c182780b8 (patch) | |
tree | b7400e262ea6c4e6d79b9b770f2508dfd6af4a37 | |
parent | 2ff6d1af902fb1b7d969e6f043798c1ebcb9ba90 (diff) | |
download | roadmap-d3a81e80937582f8eb5212296d68104c182780b8.tar.gz |
Change: dependencies() to return iterator over &str
This avoids making temporary, pointless copies of Strings.
-rw-r--r-- | src/parser.rs | 4 | ||||
-rw-r--r-- | src/step.rs | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/parser.rs b/src/parser.rs index 60bbf2a..411c074 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -160,13 +160,13 @@ second: let first = roadmap.get_step("first").unwrap(); assert_eq!(first.name(), "first"); assert_eq!(first.label(), "the first step"); - let deps: Vec<&String> = first.dependencies().collect(); + let deps: Vec<&str> = first.dependencies().collect(); assert_eq!(deps.len(), 0); let second = roadmap.get_step("second").unwrap(); assert_eq!(second.name(), "second"); assert_eq!(second.label(), "the second step"); - let deps: Vec<&String> = second.dependencies().collect(); + let deps: Vec<&str> = second.dependencies().collect(); assert_eq!(deps, vec!["first"]); } } diff --git a/src/step.rs b/src/step.rs index a37f23c..6088400 100644 --- a/src/step.rs +++ b/src/step.rs @@ -45,8 +45,8 @@ impl Step { } /// Return vector of names of dependencies for a step. - pub fn dependencies(&self) -> impl Iterator<Item = &String> { - self.depends.iter() + pub fn dependencies(&self) -> impl Iterator<Item = &str> { + self.depends.iter().map(|s| s.as_str()) } /// Add the name of a dependency to step. Steps are referred by @@ -86,7 +86,7 @@ mod tests { fn add_step_dependency() { let mut second = Step::new("second", "the second step"); second.add_dependency("first"); - let deps: Vec<&String> = second.dependencies().collect(); + let deps: Vec<&str> = second.dependencies().collect(); assert_eq!(deps, vec!["first"]); } } |