mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-23 18:29:50 -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.
|
// TODO this would be better implemented as a Trait I think.
|
||||||
pub struct AstWalker<'a> {
|
pub struct AstWalker<'a> {
|
||||||
handle_value: Option<&'a Fn(&mut Value)>,
|
handle_value: Option<&'a dyn Fn(&mut Value)>,
|
||||||
handle_expression: Option<&'a Fn(&mut Expression)>,
|
handle_expression: Option<&'a dyn Fn(&mut Expression)>,
|
||||||
handle_statment: Option<&'a Fn(&mut Statement)>,
|
handle_statment: Option<&'a dyn Fn(&mut Statement)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AstWalker<'a> {
|
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.handle_value = Some(h);
|
||||||
self
|
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.handle_expression = Some(h);
|
||||||
self
|
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.handle_statment = Some(h);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ impl EnvConverter {
|
|||||||
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() {
|
for &(ref name, ref val) in flds.iter() {
|
||||||
if val.is_tuple() {
|
if val.is_tuple() {
|
||||||
eprintln!("Skipping embedded tuple...");
|
eprintln!("Skipping embedded tuple...");
|
||||||
@ -44,12 +44,12 @@ impl EnvConverter {
|
|||||||
Ok(())
|
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...");
|
eprintln!("Skipping List...");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&self, v: &Val, w: &mut IOWrite) -> ConvertResult {
|
fn write(&self, v: &Val, w: &mut dyn IOWrite) -> ConvertResult {
|
||||||
match v {
|
match v {
|
||||||
&Val::Empty => {
|
&Val::Empty => {
|
||||||
// Empty is a noop.
|
// Empty is a noop.
|
||||||
@ -91,7 +91,7 @@ impl EnvConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Converter for 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)
|
self.write(&v, &mut w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ impl ExecConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_assignments)]
|
#[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.
|
// We always expect the Val to be a Tuple.
|
||||||
if let &Tuple(ref fields) = v {
|
if let &Tuple(ref fields) = v {
|
||||||
// We expect no more than three fields in our exec tuple.
|
// We expect no more than three fields in our exec tuple.
|
||||||
@ -173,7 +173,7 @@ impl ExecConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Converter for 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)
|
self.write(&v, &mut w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ impl FlagConverter {
|
|||||||
self
|
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 {
|
if name.chars().count() > 1 || pfx.chars().count() > 0 {
|
||||||
write!(w, "--{}{} ", pfx, name)?;
|
write!(w, "--{}{} ", pfx, name)?;
|
||||||
} else {
|
} else {
|
||||||
@ -50,7 +50,7 @@ impl FlagConverter {
|
|||||||
pfx: &str,
|
pfx: &str,
|
||||||
name: &str,
|
name: &str,
|
||||||
def: &Vec<Rc<Val>>,
|
def: &Vec<Rc<Val>>,
|
||||||
w: &mut Write,
|
w: &mut dyn Write,
|
||||||
) -> ConvertResult {
|
) -> ConvertResult {
|
||||||
// first of all we need to make sure that each &Val is only a primitive type.
|
// first of all we need to make sure that each &Val is only a primitive type.
|
||||||
for v in def.iter() {
|
for v in def.iter() {
|
||||||
@ -68,7 +68,7 @@ impl FlagConverter {
|
|||||||
return Ok(());
|
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 {
|
match v {
|
||||||
&Val::Empty => {
|
&Val::Empty => {
|
||||||
// Empty is a noop.
|
// Empty is a noop.
|
||||||
@ -94,7 +94,7 @@ impl FlagConverter {
|
|||||||
Ok(())
|
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() {
|
for &(ref name, ref val) in flds.iter() {
|
||||||
if let &Val::Empty = val.as_ref() {
|
if let &Val::Empty = val.as_ref() {
|
||||||
self.write_flag_name(pfx, name, w)?;
|
self.write_flag_name(pfx, name, w)?;
|
||||||
@ -118,7 +118,7 @@ impl FlagConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Converter for 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() {
|
if let &Val::Tuple(ref flds) = v.as_ref() {
|
||||||
self.write("", flds, &mut w)
|
self.write("", flds, &mut w)
|
||||||
} else {
|
} 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)?;
|
let jsn_val = self.convert_value(v)?;
|
||||||
serde_json::to_writer_pretty(w, &jsn_val)?;
|
serde_json::to_writer_pretty(w, &jsn_val)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -124,7 +124,7 @@ impl JsonConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Converter for 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)
|
self.write(&v, &mut w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,15 +55,15 @@ impl ConverterRegistry {
|
|||||||
registry
|
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);
|
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())
|
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()
|
self.converters.iter().collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ use crate::convert::traits::{ConvertResult, Converter, ImportResult, Importer};
|
|||||||
|
|
||||||
pub struct TomlConverter {}
|
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 {
|
impl TomlConverter {
|
||||||
pub fn new() -> Self {
|
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_val = self.convert_value(v)?;
|
||||||
let toml_bytes = toml::ser::to_string_pretty(&toml_val)?;
|
let toml_bytes = toml::ser::to_string_pretty(&toml_val)?;
|
||||||
write!(w, "{}", toml_bytes)?;
|
write!(w, "{}", toml_bytes)?;
|
||||||
@ -116,7 +116,7 @@ impl TomlConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Converter for 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)
|
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
|
/// The trait that Converters from Val to different output formats for the
|
||||||
/// final conversion stage of the ucg compiler.
|
/// final conversion stage of the ucg compiler.
|
||||||
pub trait Converter {
|
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 file_ext(&self) -> String;
|
||||||
fn description(&self) -> String;
|
fn description(&self) -> String;
|
||||||
fn help(&self) -> String;
|
fn help(&self) -> String;
|
||||||
|
@ -153,7 +153,7 @@ impl XmlConverter {
|
|||||||
Ok(())
|
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 {
|
if let Val::Tuple(ref fs) = v {
|
||||||
let mut version: Option<&str> = None;
|
let mut version: Option<&str> = None;
|
||||||
let mut encoding: Option<&str> = None;
|
let mut encoding: Option<&str> = None;
|
||||||
@ -223,7 +223,7 @@ impl XmlConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Converter for 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)
|
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)?;
|
let jsn_val = self.convert_value(v)?;
|
||||||
serde_yaml::to_writer(w, &jsn_val)?;
|
serde_yaml::to_writer(w, &jsn_val)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -147,7 +147,7 @@ impl YamlConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Converter for 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)
|
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 {
|
fn run_converter(c: &dyn traits::Converter, v: Rc<Val>, f: Option<&str>) -> traits::ConvertResult {
|
||||||
let mut file: Box<std::io::Write> = match f {
|
let mut file: Box<dyn std::io::Write> = match f {
|
||||||
Some(f) => {
|
Some(f) => {
|
||||||
let mut path_buf = PathBuf::from(f);
|
let mut path_buf = PathBuf::from(f);
|
||||||
path_buf.set_extension(c.file_ext());
|
path_buf.set_extension(c.file_ext());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user