mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
MAINT: cargo fix
Mostly to add the dyn keyword all the places where it will soon be required.
This commit is contained in:
parent
97c25e076f
commit
49a64251a4
@ -124,9 +124,9 @@ pub trait Walker {
|
||||
|
||||
// TODO this would be better implemented as a Trait I think.
|
||||
pub struct AstWalker<'a> {
|
||||
handle_value: Option<&'a Fn(&mut Value)>,
|
||||
handle_expression: Option<&'a Fn(&mut Expression)>,
|
||||
handle_statment: Option<&'a Fn(&mut Statement)>,
|
||||
handle_value: Option<&'a dyn Fn(&mut Value)>,
|
||||
handle_expression: Option<&'a dyn Fn(&mut Expression)>,
|
||||
handle_statment: Option<&'a dyn Fn(&mut Statement)>,
|
||||
}
|
||||
|
||||
impl<'a> AstWalker<'a> {
|
||||
@ -138,17 +138,17 @@ impl<'a> AstWalker<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_value_handler(mut self, h: &'a Fn(&mut Value)) -> Self {
|
||||
pub fn with_value_handler(mut self, h: &'a dyn Fn(&mut Value)) -> Self {
|
||||
self.handle_value = Some(h);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_expr_handler(mut self, h: &'a Fn(&mut Expression)) -> Self {
|
||||
pub fn with_expr_handler(mut self, h: &'a dyn Fn(&mut Expression)) -> Self {
|
||||
self.handle_expression = Some(h);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_stmt_handler(mut self, h: &'a Fn(&mut Statement)) -> Self {
|
||||
pub fn with_stmt_handler(mut self, h: &'a dyn Fn(&mut Statement)) -> Self {
|
||||
self.handle_statment = Some(h);
|
||||
self
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ impl EnvConverter {
|
||||
EnvConverter {}
|
||||
}
|
||||
|
||||
fn convert_tuple(&self, flds: &Vec<(String, Rc<Val>)>, w: &mut IOWrite) -> ConvertResult {
|
||||
fn convert_tuple(&self, flds: &Vec<(String, Rc<Val>)>, w: &mut dyn IOWrite) -> ConvertResult {
|
||||
for &(ref name, ref val) in flds.iter() {
|
||||
if val.is_tuple() {
|
||||
eprintln!("Skipping embedded tuple...");
|
||||
@ -44,12 +44,12 @@ impl EnvConverter {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn convert_list(&self, _items: &Vec<Rc<Val>>, _w: &mut IOWrite) -> ConvertResult {
|
||||
fn convert_list(&self, _items: &Vec<Rc<Val>>, _w: &mut dyn IOWrite) -> ConvertResult {
|
||||
eprintln!("Skipping List...");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write(&self, v: &Val, w: &mut IOWrite) -> ConvertResult {
|
||||
fn write(&self, v: &Val, w: &mut dyn IOWrite) -> ConvertResult {
|
||||
match v {
|
||||
&Val::Empty => {
|
||||
// Empty is a noop.
|
||||
@ -91,7 +91,7 @@ impl EnvConverter {
|
||||
}
|
||||
|
||||
impl Converter for EnvConverter {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut IOWrite) -> ConvertResult {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut dyn IOWrite) -> ConvertResult {
|
||||
self.write(&v, &mut w)
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ impl ExecConverter {
|
||||
}
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
fn write(&self, v: &Val, w: &mut Write) -> ConvertResult {
|
||||
fn write(&self, v: &Val, w: &mut dyn 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.
|
||||
@ -173,7 +173,7 @@ impl ExecConverter {
|
||||
}
|
||||
|
||||
impl Converter for ExecConverter {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut Write) -> ConvertResult {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut dyn Write) -> ConvertResult {
|
||||
self.write(&v, &mut w)
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ impl FlagConverter {
|
||||
self
|
||||
}
|
||||
|
||||
fn write_flag_name(&self, pfx: &str, name: &str, w: &mut Write) -> ConvertResult {
|
||||
fn write_flag_name(&self, pfx: &str, name: &str, w: &mut dyn Write) -> ConvertResult {
|
||||
if name.chars().count() > 1 || pfx.chars().count() > 0 {
|
||||
write!(w, "--{}{} ", pfx, name)?;
|
||||
} else {
|
||||
@ -50,7 +50,7 @@ impl FlagConverter {
|
||||
pfx: &str,
|
||||
name: &str,
|
||||
def: &Vec<Rc<Val>>,
|
||||
w: &mut Write,
|
||||
w: &mut dyn Write,
|
||||
) -> ConvertResult {
|
||||
// first of all we need to make sure that each &Val is only a primitive type.
|
||||
for v in def.iter() {
|
||||
@ -68,7 +68,7 @@ impl FlagConverter {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn write_simple_value(&self, v: &Val, w: &mut Write) -> ConvertResult {
|
||||
fn write_simple_value(&self, v: &Val, w: &mut dyn Write) -> ConvertResult {
|
||||
match v {
|
||||
&Val::Empty => {
|
||||
// Empty is a noop.
|
||||
@ -94,7 +94,7 @@ impl FlagConverter {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write(&self, pfx: &str, flds: &Vec<(String, Rc<Val>)>, w: &mut Write) -> ConvertResult {
|
||||
fn write(&self, pfx: &str, flds: &Vec<(String, Rc<Val>)>, w: &mut dyn Write) -> ConvertResult {
|
||||
for &(ref name, ref val) in flds.iter() {
|
||||
if let &Val::Empty = val.as_ref() {
|
||||
self.write_flag_name(pfx, name, w)?;
|
||||
@ -118,7 +118,7 @@ impl FlagConverter {
|
||||
}
|
||||
|
||||
impl Converter for FlagConverter {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut Write) -> ConvertResult {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut dyn Write) -> ConvertResult {
|
||||
if let &Val::Tuple(ref flds) = v.as_ref() {
|
||||
self.write("", flds, &mut w)
|
||||
} else {
|
||||
|
@ -116,7 +116,7 @@ impl JsonConverter {
|
||||
})
|
||||
}
|
||||
|
||||
fn write(&self, v: &Val, w: &mut Write) -> ConvertResult {
|
||||
fn write(&self, v: &Val, w: &mut dyn Write) -> ConvertResult {
|
||||
let jsn_val = self.convert_value(v)?;
|
||||
serde_json::to_writer_pretty(w, &jsn_val)?;
|
||||
Ok(())
|
||||
@ -124,7 +124,7 @@ impl JsonConverter {
|
||||
}
|
||||
|
||||
impl Converter for JsonConverter {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut Write) -> ConvertResult {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut dyn Write) -> ConvertResult {
|
||||
self.write(&v, &mut w)
|
||||
}
|
||||
|
||||
|
@ -55,15 +55,15 @@ impl ConverterRegistry {
|
||||
registry
|
||||
}
|
||||
|
||||
pub fn register<S: Into<String>>(&mut self, typ: S, converter: Box<traits::Converter>) {
|
||||
pub fn register<S: Into<String>>(&mut self, typ: S, converter: Box<dyn traits::Converter>) {
|
||||
self.converters.insert(typ.into(), converter);
|
||||
}
|
||||
|
||||
pub fn get_converter(&self, typ: &str) -> Option<&traits::Converter> {
|
||||
pub fn get_converter(&self, typ: &str) -> Option<&dyn traits::Converter> {
|
||||
self.converters.get(typ).map(|c| c.as_ref())
|
||||
}
|
||||
|
||||
pub fn get_converter_list(&self) -> Vec<(&String, &Box<traits::Converter>)> {
|
||||
pub fn get_converter_list(&self) -> Vec<(&String, &Box<dyn traits::Converter>)> {
|
||||
self.converters.iter().collect()
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ use crate::convert::traits::{ConvertResult, Converter, ImportResult, Importer};
|
||||
|
||||
pub struct TomlConverter {}
|
||||
|
||||
type Result = std::result::Result<toml::Value, Box<error::Error>>;
|
||||
type Result = std::result::Result<toml::Value, Box<dyn error::Error>>;
|
||||
|
||||
impl TomlConverter {
|
||||
pub fn new() -> Self {
|
||||
@ -107,7 +107,7 @@ impl TomlConverter {
|
||||
})
|
||||
}
|
||||
|
||||
fn write(&self, v: &Val, w: &mut Write) -> ConvertResult {
|
||||
fn write(&self, v: &Val, w: &mut dyn Write) -> ConvertResult {
|
||||
let toml_val = self.convert_value(v)?;
|
||||
let toml_bytes = toml::ser::to_string_pretty(&toml_val)?;
|
||||
write!(w, "{}", toml_bytes)?;
|
||||
@ -116,7 +116,7 @@ impl TomlConverter {
|
||||
}
|
||||
|
||||
impl Converter for TomlConverter {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut Write) -> ConvertResult {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut dyn Write) -> ConvertResult {
|
||||
self.write(&v, &mut w)
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ pub type ImportResult = result::Result<Rc<Val>, Box<dyn Error>>;
|
||||
/// 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<Val>, w: &mut Write) -> ConvertResult;
|
||||
fn convert(&self, vs: Rc<Val>, w: &mut dyn Write) -> ConvertResult;
|
||||
fn file_ext(&self) -> String;
|
||||
fn description(&self) -> String;
|
||||
fn help(&self) -> String;
|
||||
|
@ -153,7 +153,7 @@ impl XmlConverter {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write(&self, v: &Val, w: &mut Write) -> ConvertResult {
|
||||
fn write(&self, v: &Val, w: &mut dyn Write) -> ConvertResult {
|
||||
if let Val::Tuple(ref fs) = v {
|
||||
let mut version: Option<&str> = None;
|
||||
let mut encoding: Option<&str> = None;
|
||||
@ -223,7 +223,7 @@ impl XmlConverter {
|
||||
}
|
||||
|
||||
impl Converter for XmlConverter {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut Write) -> ConvertResult {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut dyn Write) -> ConvertResult {
|
||||
self.write(&v, &mut w)
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ impl YamlConverter {
|
||||
})
|
||||
}
|
||||
|
||||
fn write(&self, v: &Val, w: &mut Write) -> ConvertResult {
|
||||
fn write(&self, v: &Val, w: &mut dyn Write) -> ConvertResult {
|
||||
let jsn_val = self.convert_value(v)?;
|
||||
serde_yaml::to_writer(w, &jsn_val)?;
|
||||
Ok(())
|
||||
@ -147,7 +147,7 @@ impl YamlConverter {
|
||||
}
|
||||
|
||||
impl Converter for YamlConverter {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut Write) -> ConvertResult {
|
||||
fn convert(&self, v: Rc<Val>, mut w: &mut dyn Write) -> ConvertResult {
|
||||
self.write(&v, &mut w)
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,8 @@ fn do_flags<'a, 'b>() -> clap::App<'a, 'b> {
|
||||
)
|
||||
}
|
||||
|
||||
fn run_converter(c: &traits::Converter, v: Rc<Val>, f: Option<&str>) -> traits::ConvertResult {
|
||||
let mut file: Box<std::io::Write> = match f {
|
||||
fn run_converter(c: &dyn traits::Converter, v: Rc<Val>, f: Option<&str>) -> traits::ConvertResult {
|
||||
let mut file: Box<dyn std::io::Write> = match f {
|
||||
Some(f) => {
|
||||
let mut path_buf = PathBuf::from(f);
|
||||
path_buf.set_extension(c.file_ext());
|
||||
|
Loading…
x
Reference in New Issue
Block a user