summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-11-07 07:33:08 +0000
committerLars Wirzenius <liw@liw.fi>2021-11-07 07:33:08 +0000
commit24f4aeebfeffd5375f8115e90e7c72824c7edf89 (patch)
tree45fa73ded222918d696d1b417fcc726456e8f2a9
parent498a88aaf124a355fb59dc0f51284ded0b8583a6 (diff)
parent86cc978aea3edb3c8b1b8674b9d24af0dc0db7cf (diff)
downloadroadmap-24f4aeebfeffd5375f8115e90e7c72824c7edf89.tar.gz
Merge branch 'cleanups' into 'main'
clean up code so it doesn't have warnings with current toolchain See merge request larswirzenius/roadmap!2
-rwxr-xr-xcheck7
-rw-r--r--src/err.rs1
-rw-r--r--src/map.rs14
-rw-r--r--src/parser.rs43
4 files changed, 30 insertions, 35 deletions
diff --git a/check b/check
new file mode 100755
index 0000000..e5d1646
--- /dev/null
+++ b/check
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+set -euo pipefail
+
+cargo clippy -q -- --deny=clippy::all
+cargo build -q --all-targets
+cargo test -q
diff --git a/src/err.rs b/src/err.rs
index 6a224a1..b928b09 100644
--- a/src/err.rs
+++ b/src/err.rs
@@ -1,4 +1,3 @@
-use serde_yaml;
use thiserror::Error;
/// Errors that can be returned for roadmaps.
diff --git a/src/map.rs b/src/map.rs
index 671318e..874e537 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -12,7 +12,7 @@ pub type RoadmapResult<T> = Result<T, RoadmapError>;
///
/// This stores all the steps needed to reach the end goal. See the
/// crate leve documentation for an example.
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, Default)]
pub struct Roadmap {
steps: Vec<Step>,
}
@@ -21,8 +21,8 @@ impl Roadmap {
/// Create a new, empty roadmap.
///
/// You probably want the `from_yaml` function instead.
- pub fn new() -> Roadmap {
- Roadmap { steps: vec![] }
+ pub fn new() -> Self {
+ Self::default()
}
// Find steps that nothing depends on.
@@ -45,7 +45,7 @@ impl Roadmap {
/// Get a step, given its name.
pub fn get_step(&self, name: &str) -> Option<&Step> {
- self.steps.iter().filter(|step| step.name() == name).next()
+ self.steps.iter().find(|step| step.name() == name)
}
/// Add a step to the roadmap.
@@ -122,7 +122,7 @@ impl Roadmap {
/// Should status be goal? In other words, does any other step
/// depend on this one?
pub fn is_goal(&self, step: &Step) -> bool {
- self.steps.iter().all(|other| !other.depends_on(&step))
+ self.steps.iter().all(|other| !other.depends_on(step))
}
// Validate that the parsed, constructed roadmap is valid.
@@ -137,7 +137,7 @@ impl Roadmap {
let names: Vec<String> = goals.iter().map(|s| s.name().into()).collect();
return Err(RoadmapError::ManyGoals {
count: n,
- names: names,
+ names,
});
}
}
@@ -169,7 +169,7 @@ impl Roadmap {
format!(
"{} [label=\"{}\" style=filled fillcolor=\"{}\" shape=\"{}\"];\n",
step.name(),
- fill(&step.label(), label_width).replace("\n", "\\n"),
+ fill(step.label(), label_width).replace("\n", "\\n"),
Roadmap::get_status_color(step),
Roadmap::get_status_shape(step),
)
diff --git a/src/parser.rs b/src/parser.rs
index 7602b94..d83f618 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,4 +1,3 @@
-use serde_yaml;
use serde_yaml::Value;
use std::collections::HashMap;
@@ -26,13 +25,13 @@ pub fn from_yaml(yaml: &str) -> RoadmapResult<Roadmap> {
fn step_from_value(name: &str, value: &Value) -> RoadmapResult<Step> {
match value {
Value::Mapping(_) => {
- let label = parse_label(&value);
- let status = parse_status(&value)?;
+ let label = parse_label(value);
+ let status = parse_status(value)?;
let mut step = Step::new(name, label);
step.set_status(status);
- for depname in parse_depends(&value)?.iter() {
+ for depname in parse_depends(value)?.iter() {
step.add_dependency(depname);
}
@@ -70,7 +69,7 @@ fn parse_label(map: &Value) -> &str {
}
// Get status string from a Mapping element. Default to unknown status.
-fn parse_status<'a>(map: &'a Value) -> RoadmapResult<Status> {
+fn parse_status(map: &Value) -> RoadmapResult<Status> {
let text = parse_string("status", map);
match Status::from_text(text) {
Some(status) => Ok(status),
@@ -94,46 +93,36 @@ mod tests {
#[test]
fn yaml_is_empty() {
- let r = from_yaml("");
- match r {
- Ok(_) => panic!("expected a parse error"),
- _ => (),
+ if from_yaml("").is_ok() {
+ panic!("expected a parse error");
}
}
#[test]
fn yaml_is_list() {
- let r = from_yaml("[]");
- match r {
- Ok(_) => panic!("expected a parse error"),
- _ => (),
+ if from_yaml("[]").is_ok() {
+ panic!("expected a parse error");
}
}
#[test]
fn yaml_map_entries_not_maps() {
- let r = from_yaml("foo: []");
- match r {
- Ok(_) => panic!("expected a parse error"),
- _ => (),
+ if from_yaml("foo: []").is_ok() {
+ panic!("expected a parse error");
}
}
#[test]
fn yaml_unknown_dep() {
- let r = from_yaml("foo: {depends: [bar]}");
- match r {
- Ok(_) => panic!("expected a parse error"),
- _ => (),
+ if from_yaml("foo: {depends: [bar]}").is_ok() {
+ panic!("expected a parse error");
}
}
#[test]
fn yaml_unknown_status() {
- let r = from_yaml(r#"foo: {status: "bar"}"#);
- match r {
- Ok(_) => panic!("expected a parse error"),
- _ => (),
+ if from_yaml(r#"foo: {status: "bar"}"#).is_ok() {
+ panic!("expected a parse error");
}
}
@@ -159,8 +148,8 @@ second:
let first = roadmap.get_step("first").unwrap();
assert_eq!(first.name(), "first");
assert_eq!(first.label(), "the first step");
- let deps: Vec<&str> = first.dependencies().collect();
- assert_eq!(deps.len(), 0);
+ let deps = first.dependencies().count();
+ assert_eq!(deps, 0);
let second = roadmap.get_step("second").unwrap();
assert_eq!(second.name(), "second");