instruction_serialiser/
negate_node.rs

1use std::collections::HashMap;
2use crate::calculation_error::CalculationError;
3use crate::generic_node::GenericNode;
4use crate::instruction_serialiser::{LogicalResultNodeWrapper, NegateNode};
5use crate::instruction_serialiser::logical_result_node_wrapper::Node;
6use crate::logical_type::LogicalType;
7use crate::node_wrapper::NodeWrapper;
8use crate::parameter::Parameter;
9
10impl GenericNode<LogicalType> for NegateNode {
11    fn calculate(&self, parameters: &HashMap<&str, Parameter>) -> Result<LogicalType, CalculationError> {
12        let node = self.child.as_ref().ok_or(
13            CalculationError::new("The child of a negate node must be present to perform a calculation")
14        )?;
15        Ok(!node.calculate_wrapped_nodes(parameters)?)
16    }
17}
18
19impl LogicalResultNodeWrapper {
20    pub fn negate(self) -> LogicalResultNodeWrapper {
21        LogicalResultNodeWrapper{
22            node: Some(
23                Node::NegateNode(
24                    Box::new(
25                        NegateNode{
26                            child: Some(
27                                Box::new(self)
28                            ),
29                        }
30                    )
31                )
32            )
33        }
34    }
35}