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§
Object Safety§
This trait is not object safe.