Trait exmex::MakeOperators

source ·
pub trait MakeOperators<T: Clone>: Clone + Debug {
    // Required method
    fn make<'a>() -> Vec<Operator<'a, T>>;
}
Expand description

To use custom operators one needs to create a factory that implements this trait. In this way, we make sure that we can deserialize expressions with serde with the correct operators based on the type.

Example

use exmex::{BinOp, MakeOperators, Operator};
#[derive(Clone, Debug)]
struct SomeOpsFactory;
impl MakeOperators<f32> for SomeOpsFactory {
    fn make<'a>() -> Vec<Operator<'a, f32>> {    
        vec![
            Operator::make_bin_unary(
                "-",
                BinOp {
                    apply: |a, b| a - b,
                    prio: 0,
                    is_commutative: false,
                },
                |a| (-a),
            ),
            Operator::make_unary("sin", |a| a.sin())
        ]
    }
}

Required Methods§

source

fn make<'a>() -> Vec<Operator<'a, T>>

Function that creates a vector of operators.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<I, F> MakeOperators<Val<I, F>> for ValOpsFactory<I, F>
where I: DataType + PrimInt + Signed, F: DataType + Float, <I as FromStr>::Err: Debug, <F as FromStr>::Err: Debug,

source§

impl<T: Debug + Float> MakeOperators<T> for FloatOpsFactory<T>