diff --git a/src/nodes/evaluate.rs b/src/nodes/evaluate.rs index 13635f8..eae3d8e 100644 --- a/src/nodes/evaluate.rs +++ b/src/nodes/evaluate.rs @@ -31,12 +31,11 @@ fn collapse_toplevel(nodes: &mut Vec, mut end: usize) { while let Some((index, variant)) = nodes[start..end] .iter() - .filter_map(|n| match n { - Node::Function(f) => Some(f), + .enumerate() + .filter_map(|(i, n)| match n { + Node::Function(f) => Some((i, *f)), _ => None, }) - .cloned() - .enumerate() .next() { match &mut nodes[start..end][index + 1] { @@ -50,7 +49,7 @@ fn collapse_toplevel(nodes: &mut Vec, mut end: usize) { Function::Secant => n.sec_mut(), Function::CoSecant => n.csc_mut(), }, - _ => panic!("function is missing an argument"), + n => panic!("function is missing an argument, got: {n:?}"), }; nodes.remove(start + index); diff --git a/src/nodes/mod.rs b/src/nodes/mod.rs index 84c7583..a7326bf 100644 --- a/src/nodes/mod.rs +++ b/src/nodes/mod.rs @@ -11,7 +11,7 @@ mod tests; pub const PREC: u32 = 512; -#[derive(Default, Debug, Clone, PartialEq)] +#[derive(Debug, Default, Clone, PartialEq)] pub struct Nodes(Vec); impl AsRef<[Node]> for Nodes { fn as_ref(&self) -> &[Node] { @@ -19,7 +19,7 @@ impl AsRef<[Node]> for Nodes { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Debug, Clone, PartialEq)] enum Node { Function(Function), ParenthesisStart, @@ -28,7 +28,7 @@ enum Node { Operator(Operator), } -#[derive(Default, Clone, Debug, PartialEq)] +#[derive(Debug, Default, Copy, Clone, PartialEq)] enum Operator { Plus, Minus, @@ -38,7 +38,7 @@ enum Operator { Exp, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq)] enum Function { Sine, ArcSine,