summaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 411c074..7da2254 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,15 +1,14 @@
use serde_yaml;
use serde_yaml::Value;
use std::collections::HashMap;
-use std::error::Error;
pub use crate::Roadmap;
-pub use crate::RoadmapError;
+pub use crate::RoadmapResult;
pub use crate::Status;
pub use crate::Step;
/// Create a new roadmap from a textual YAML representation.
-pub fn from_yaml(yaml: &str) -> Result<Roadmap, Box<dyn Error>> {
+pub fn from_yaml(yaml: &str) -> RoadmapResult<Roadmap> {
let mut roadmap = Roadmap::new();
let map: HashMap<String, serde_yaml::Value> = serde_yaml::from_str(yaml)?;
@@ -23,7 +22,7 @@ pub fn from_yaml(yaml: &str) -> Result<Roadmap, Box<dyn Error>> {
}
// Convert a Value into a Step, if possible.
-fn step_from_value(name: &str, value: &Value) -> RoadmapError<Step> {
+fn step_from_value(name: &str, value: &Value) -> RoadmapResult<Step> {
match value {
Value::Mapping(_) => {
let label = parse_label(&value);
@@ -38,12 +37,12 @@ fn step_from_value(name: &str, value: &Value) -> RoadmapError<Step> {
Ok(step)
}
- _ => Err("step is not a mapping".to_string()),
+ _ => Err("step is not a mapping".to_string().into()),
}
}
// Get a sequence of depenencies.
-fn parse_depends(map: &Value) -> RoadmapError<Vec<&str>> {
+fn parse_depends(map: &Value) -> RoadmapResult<Vec<&str>> {
let key_name = "depends";
let key = Value::String(key_name.to_string());
let mut depends: Vec<&str> = vec![];
@@ -55,11 +54,11 @@ fn parse_depends(map: &Value) -> RoadmapError<Vec<&str>> {
for depname in deps.iter() {
match depname {
Value::String(depname) => depends.push(depname),
- _ => return Err(need_list_of_names),
+ _ => return Err(need_list_of_names.into()),
}
}
}
- _ => return Err(need_list_of_names),
+ _ => return Err(need_list_of_names.into()),
}
Ok(depends)
@@ -71,11 +70,11 @@ fn parse_label(map: &Value) -> &str {
}
// Get status string from a Mapping element. Default to unknown status.
-fn parse_status<'a>(map: &'a Value) -> RoadmapError<Status> {
+fn parse_status<'a>(map: &'a Value) -> RoadmapResult<Status> {
let text = parse_string("status", map);
match Status::from_text(text) {
Some(status) => Ok(status),
- _ => Err(format!("unknown status: {:?}", text)),
+ _ => Err(format!("unknown status: {:?}", text).into()),
}
}