diff --git a/src/convert/env.rs b/src/convert/env.rs index 2e3198b..9fde39e 100644 --- a/src/convert/env.rs +++ b/src/convert/env.rs @@ -18,7 +18,7 @@ use std::rc::Rc; use crate::ast::PositionedItem; use crate::build::Val; -use crate::convert::traits::{Converter, Result}; +use crate::convert::traits::{ConvertResult, Converter}; /// EnvConverter implements the conversion logic for converting a Val into a /// set of environment variables. @@ -33,7 +33,7 @@ impl EnvConverter { &self, flds: &Vec<(PositionedItem, Rc)>, w: &mut Write, - ) -> Result { + ) -> ConvertResult { for &(ref name, ref val) in flds.iter() { if val.is_tuple() { eprintln!("Skipping embedded tuple..."); @@ -49,12 +49,12 @@ impl EnvConverter { Ok(()) } - fn convert_list(&self, _items: &Vec>, _w: &mut Write) -> Result { + fn convert_list(&self, _items: &Vec>, _w: &mut Write) -> ConvertResult { eprintln!("Skipping List..."); Ok(()) } - fn write(&self, v: &Val, w: &mut Write) -> Result { + fn write(&self, v: &Val, w: &mut Write) -> ConvertResult { match v { &Val::Empty => { // Empty is a noop. @@ -96,7 +96,7 @@ impl EnvConverter { } impl Converter for EnvConverter { - fn convert(&self, v: Rc, mut w: &mut Write) -> Result { + fn convert(&self, v: Rc, mut w: &mut Write) -> ConvertResult { self.write(&v, &mut w) } diff --git a/src/convert/exec.rs b/src/convert/exec.rs index b372fc2..b24a8b8 100644 --- a/src/convert/exec.rs +++ b/src/convert/exec.rs @@ -21,7 +21,7 @@ use crate::ast::{Position, PositionedItem}; use crate::build::Val; use crate::build::Val::Tuple; use crate::convert; -use crate::convert::traits::{Converter, Result}; +use crate::convert::traits::{ConvertResult, Converter}; use crate::error::BuildError; use crate::error::ErrorType; @@ -38,7 +38,7 @@ impl ExecConverter { } #[allow(unused_assignments)] - fn write(&self, v: &Val, w: &mut Write) -> Result { + fn write(&self, v: &Val, w: &mut Write) -> ConvertResult { // We always expect the Val to be a Tuple. if let &Tuple(ref fields) = v { // We expect no more than three fields in our exec tuple. @@ -179,7 +179,7 @@ impl ExecConverter { } impl Converter for ExecConverter { - fn convert(&self, v: Rc, mut w: &mut Write) -> Result { + fn convert(&self, v: Rc, mut w: &mut Write) -> ConvertResult { self.write(&v, &mut w) } diff --git a/src/convert/flags.rs b/src/convert/flags.rs index 8a24e6a..c245d55 100644 --- a/src/convert/flags.rs +++ b/src/convert/flags.rs @@ -17,7 +17,7 @@ use std::io::Write; use std::rc::Rc; use crate::build::Val; -use crate::convert::traits::{Converter, Result}; +use crate::convert::traits::{ConvertResult, Converter}; /// FlagConverter implements the conversion logic for converting a Val into a set /// of command line flags. @@ -28,7 +28,7 @@ impl FlagConverter { FlagConverter {} } - fn write_flag_name(&self, pfx: &str, name: &str, w: &mut Write) -> Result { + fn write_flag_name(&self, pfx: &str, name: &str, w: &mut Write) -> ConvertResult { if name.chars().count() > 1 || pfx.chars().count() > 0 { write!(w, "--{}{} ", pfx, name)?; } else { @@ -37,7 +37,13 @@ impl FlagConverter { return Ok(()); } - fn write_list_flag(&self, pfx: &str, name: &str, def: &Vec>, w: &mut Write) -> Result { + fn write_list_flag( + &self, + pfx: &str, + name: &str, + def: &Vec>, + w: &mut Write, + ) -> ConvertResult { // first of all we need to make sure that each &Val is only a primitive type. for v in def.iter() { let vref = v.as_ref(); @@ -54,7 +60,7 @@ impl FlagConverter { return Ok(()); } - fn write(&self, pfx: &str, v: &Val, w: &mut Write) -> Result { + fn write(&self, pfx: &str, v: &Val, w: &mut Write) -> ConvertResult { match v { &Val::Empty => { // Empty is a noop. @@ -114,7 +120,7 @@ impl FlagConverter { } impl Converter for FlagConverter { - fn convert(&self, v: Rc, mut w: &mut Write) -> Result { + fn convert(&self, v: Rc, mut w: &mut Write) -> ConvertResult { self.write("", &v, &mut w) } diff --git a/src/convert/json.rs b/src/convert/json.rs index 3bd8935..89ccaa6 100644 --- a/src/convert/json.rs +++ b/src/convert/json.rs @@ -17,7 +17,7 @@ use serde_json; use crate::ast; use crate::build::Val; -use crate::convert::traits::{Converter, ImportResult, Importer, Result}; +use crate::convert::traits::{ConvertResult, Converter, ImportResult, Importer}; /// JsonConverter implements the logic for converting a Val into the json output format. pub struct JsonConverter {} @@ -123,7 +123,7 @@ impl JsonConverter { }) } - fn write(&self, v: &Val, w: &mut Write) -> Result { + fn write(&self, v: &Val, w: &mut Write) -> ConvertResult { let jsn_val = self.convert_value(v)?; serde_json::to_writer_pretty(w, &jsn_val)?; Ok(()) @@ -131,7 +131,7 @@ impl JsonConverter { } impl Converter for JsonConverter { - fn convert(&self, v: Rc, mut w: &mut Write) -> Result { + fn convert(&self, v: Rc, mut w: &mut Write) -> ConvertResult { self.write(&v, &mut w) } diff --git a/src/convert/toml.rs b/src/convert/toml.rs index 1e6f651..2b34e63 100644 --- a/src/convert/toml.rs +++ b/src/convert/toml.rs @@ -22,18 +22,18 @@ use toml; use crate::ast; use crate::build::Val; -use crate::convert::traits::{Converter, Result}; +use crate::convert::traits::{ConvertResult, Converter}; pub struct TomlConverter {} -type ConvertResult = std::result::Result>; +type Result = std::result::Result>; impl TomlConverter { pub fn new() -> Self { TomlConverter {} } - fn convert_list(&self, items: &Vec>) -> ConvertResult { + fn convert_list(&self, items: &Vec>) -> Result { let mut v = Vec::new(); for val in items.iter() { v.push(self.convert_value(val)?); @@ -41,7 +41,7 @@ impl TomlConverter { Ok(toml::Value::Array(v)) } - fn convert_tuple(&self, items: &Vec<(ast::PositionedItem, Rc)>) -> ConvertResult { + fn convert_tuple(&self, items: &Vec<(ast::PositionedItem, Rc)>) -> Result { let mut mp = toml::value::Table::new(); for &(ref k, ref v) in items.iter() { mp.entry(k.val.clone()).or_insert(self.convert_value(v)?); @@ -49,7 +49,7 @@ impl TomlConverter { Ok(toml::Value::Table(mp)) } - fn convert_env(&self, items: &Vec<(String, String)>) -> ConvertResult { + fn convert_env(&self, items: &Vec<(String, String)>) -> Result { let mut mp = toml::value::Table::new(); for &(ref k, ref v) in items.iter() { mp.entry(k.clone()) @@ -58,7 +58,7 @@ impl TomlConverter { Ok(toml::Value::Table(mp)) } - fn convert_value(&self, v: &Val) -> ConvertResult { + fn convert_value(&self, v: &Val) -> Result { let toml_val = match v { &Val::Boolean(b) => toml::Value::Boolean(b), // TODO(jwall): This is an error apparently @@ -84,7 +84,7 @@ impl TomlConverter { Ok(toml_val) } - fn write(&self, v: &Val, w: &mut Write) -> Result { + fn write(&self, v: &Val, w: &mut Write) -> ConvertResult { let toml_val = self.convert_value(v)?; let toml_bytes = toml::ser::to_string_pretty(&toml_val)?; write!(w, "{}", toml_bytes)?; @@ -93,7 +93,7 @@ impl TomlConverter { } impl Converter for TomlConverter { - fn convert(&self, v: Rc, mut w: &mut Write) -> Result { + fn convert(&self, v: Rc, mut w: &mut Write) -> ConvertResult { self.write(&v, &mut w) } diff --git a/src/convert/traits.rs b/src/convert/traits.rs index 89decc0..37cd3ba 100644 --- a/src/convert/traits.rs +++ b/src/convert/traits.rs @@ -21,14 +21,14 @@ use std::result; use crate::build::Val; // TODO Rename to ConvertResult -pub type Result = result::Result<(), Box>; +pub type ConvertResult = result::Result<(), Box>; pub type ImportResult = result::Result, Box>; /// The trait that Converters from Val to different output formats for the /// final conversion stage of the ucg compiler. pub trait Converter { - fn convert(&self, vs: Rc, w: &mut Write) -> Result; + fn convert(&self, vs: Rc, w: &mut Write) -> ConvertResult; fn file_ext(&self) -> String; fn description(&self) -> String; } diff --git a/src/convert/xml.rs b/src/convert/xml.rs index 4619747..1e10bc3 100644 --- a/src/convert/xml.rs +++ b/src/convert/xml.rs @@ -17,7 +17,7 @@ use std::error::Error; use std::io::Write; use std::rc::Rc; -use super::traits::{Converter, Result}; +use super::traits::{ConvertResult, Converter}; use crate::ast::{Position, PositionedItem}; use crate::build::Val; use crate::error::BuildError; @@ -69,7 +69,7 @@ impl XmlConverter { } } - fn write_node(&self, v: &Val, w: &mut EventWriter) -> Result { + fn write_node(&self, v: &Val, w: &mut EventWriter) -> ConvertResult { // First we determine if this is a tag or text node if let Val::Tuple(ref fs) = v { let mut name: Option<&str> = None; @@ -168,7 +168,7 @@ impl XmlConverter { Ok(()) } - fn write(&self, v: &Val, w: &mut Write) -> Result { + fn write(&self, v: &Val, w: &mut Write) -> ConvertResult { if let Val::Tuple(ref fs) = v { let mut version: Option<&str> = None; let mut encoding: Option<&str> = None; @@ -242,7 +242,7 @@ impl XmlConverter { } impl Converter for XmlConverter { - fn convert(&self, v: Rc, mut w: &mut Write) -> Result { + fn convert(&self, v: Rc, mut w: &mut Write) -> ConvertResult { self.write(&v, &mut w) } diff --git a/src/convert/yaml.rs b/src/convert/yaml.rs index 391d224..4cd0f51 100644 --- a/src/convert/yaml.rs +++ b/src/convert/yaml.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use serde_yaml; -use super::traits::{Converter, Result}; +use super::traits::{ConvertResult, Converter}; use crate::ast; use crate::build::Val; @@ -76,7 +76,7 @@ impl YamlConverter { Ok(yaml_val) } - fn write(&self, v: &Val, w: &mut Write) -> Result { + fn write(&self, v: &Val, w: &mut Write) -> ConvertResult { let jsn_val = self.convert_value(v)?; serde_yaml::to_writer(w, &jsn_val)?; Ok(()) @@ -84,7 +84,7 @@ impl YamlConverter { } impl Converter for YamlConverter { - fn convert(&self, v: Rc, mut w: &mut Write) -> Result { + fn convert(&self, v: Rc, mut w: &mut Write) -> ConvertResult { self.write(&v, &mut w) } diff --git a/src/main.rs b/src/main.rs index 4843227..bf7397b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ fn do_flags<'a, 'b>() -> clap::App<'a, 'b> { ) } -fn run_converter(c: &traits::Converter, v: Rc, f: Option<&str>) -> traits::Result { +fn run_converter(c: &traits::Converter, v: Rc, f: Option<&str>) -> traits::ConvertResult { let mut file: Box = match f { Some(f) => { let mut path_buf = PathBuf::from(f);