Trait exmex::MakeOperators[][src]

pub trait MakeOperators<T: Clone>: Clone {
    fn make<'a>() -> Vec<Operator<'a, T>>
Notable traits for Vec<u8, A>
impl<A> Write for Vec<u8, A> where
    A: Allocator
; }
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)]
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

Function that creates a vector of operators.

Implementors