summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-09-26 11:09:38 +0300
committerLars Wirzenius <liw@liw.fi>2019-09-26 11:09:38 +0300
commit58011577ec6fdc8264659f2e3456ae6ff4b4f39f (patch)
tree4050aafaeedbaab1de6eda5a361016d4efcfab15 /src
parent0b22c103aa735a14a00e8fe03bdf3027d123a36d (diff)
downloadroadmap-58011577ec6fdc8264659f2e3456ae6ff4b4f39f.tar.gz
Change: use custom result type, for brevity
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 32c880a..2ab1ecb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -33,7 +33,6 @@ use serde_yaml;
use serde_yaml::Value;
use std::collections::HashMap;
use textwrap::fill;
-use std::fmt;
use std::error::Error;
/// A step in a roadmap.
@@ -92,22 +91,14 @@ impl Step {
}
}
+/// Result type for roadmap parsing.
+type ParseResult<T> = Result<T, String>;
+
/// All the steps to get to the end goal.
pub struct Roadmap {
steps: Vec<Step>,
}
-#[derive(Debug)]
-struct ParseError(String);
-
-impl fmt::Display for ParseError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "ERROR: {}", self.0)
- }
-}
-
-impl Error for ParseError {}
-
impl Roadmap {
/// Create a new, empty roadmap.
pub fn new() -> Roadmap {
@@ -185,7 +176,7 @@ impl Roadmap {
}
// Validate that the parsed, constructed roadmap is valid.
- fn validate(&self) -> Result<(), Box<dyn std::error::Error>> {
+ fn validate(&self) -> ParseResult<()> {
// Does every step has an acceptable status?
for step in self.steps.iter() {
let status = step.status();
@@ -194,7 +185,7 @@ impl Roadmap {
_ => {
let msg = format!("step {:?} status {:?} is not allowed",
step.name(), status);
- return Result::Err(Box::new(ParseError(msg.into())));
+ return Err(msg);
}
}
}
@@ -206,7 +197,7 @@ impl Roadmap {
None => {
let msg = format!("step {} depends on missing {}",
step.name(), depname);
- return Result::Err(Box::new(ParseError(msg.into())));
+ return Err(msg);
}
Some(_) => (),
}