diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-09-26 11:09:38 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-09-26 11:09:38 +0300 |
commit | 58011577ec6fdc8264659f2e3456ae6ff4b4f39f (patch) | |
tree | 4050aafaeedbaab1de6eda5a361016d4efcfab15 /src/lib.rs | |
parent | 0b22c103aa735a14a00e8fe03bdf3027d123a36d (diff) | |
download | roadmap-58011577ec6fdc8264659f2e3456ae6ff4b4f39f.tar.gz |
Change: use custom result type, for brevity
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 21 |
1 files changed, 6 insertions, 15 deletions
@@ -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(_) => (), } |