clippy suggestions
This commit is contained in:
@@ -27,7 +27,7 @@ impl Function {
|
||||
}
|
||||
self.args
|
||||
.iter()
|
||||
.zip(args.into_iter())
|
||||
.zip(args)
|
||||
.for_each(|(p, a)| ctx.assign(p.clone(), a));
|
||||
for i in self.ins.iter() {
|
||||
i.run(ctx, globals)?;
|
||||
@@ -37,20 +37,22 @@ impl Function {
|
||||
|
||||
pub fn from(fun: &Node<'_, '_>) -> Result<Function, Box<dyn Error>> {
|
||||
Ok(Function {
|
||||
args: util::find_node(&fun, "arguments")
|
||||
args: util::find_node(fun, "arguments")
|
||||
.ok_or(MissingChild("call", "arguments"))?
|
||||
.children()
|
||||
.filter(Node::is_element)
|
||||
.map(|n| n.attribute("name").and_then(|s| Some(String::from(s))))
|
||||
.map(|n| n.attribute("name").map(String::from))
|
||||
.collect::<Option<Vec<String>>>()
|
||||
.ok_or(Unnamed("argument"))?,
|
||||
ins: Instruction::from_children(
|
||||
util::find_node(&fun, "body").ok_or(MissingChild("call", "body"))?,
|
||||
util::find_node(fun, "body").ok_or(MissingChild("call", "body"))?,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type StdFn = fn(Vec<Value>) -> Result<Option<Value>, Box<dyn Error>>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Value {
|
||||
Integer(i64),
|
||||
@@ -58,7 +60,7 @@ pub enum Value {
|
||||
String(String),
|
||||
Array(Rc<RefCell<Vec<Value>>>),
|
||||
Function(Function),
|
||||
StdFunction(fn(Vec<Value>) -> Result<Option<Value>, Box<dyn Error>>),
|
||||
StdFunction(StdFn),
|
||||
}
|
||||
|
||||
impl Value {
|
||||
@@ -66,7 +68,7 @@ impl Value {
|
||||
match self {
|
||||
Value::Integer(i) => *i != 0,
|
||||
Value::Real(f) => *f != 0.0,
|
||||
Value::String(s) => s.len() != 0,
|
||||
Value::String(s) => !s.is_empty(),
|
||||
Value::Array(v) => v.borrow().len() != 0,
|
||||
_ => true,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user