bertiqwerty / exmex

Math parser and evaluator in Rust, capable of partial differentiation, allows the use of custom operators.
Apache License 2.0
39 stars 6 forks source link

How to implement Val for i64 and f64 #50

Closed hanusek closed 11 months ago

hanusek commented 11 months ago

Hello @bertiqwerty I trying wrap FlaxEx in my struct:

#[derive(Debug, Clone, PartialOrd, PartialEq, Validate)]
pub struct QuickExpression {
    #[validate(length(min = 1), custom = "validate_expression")]
    raw_text: String,
    //expr: exmex::FlatEx<exmex::Val, exmex::ValOpsFactory, exmex::ValMatcher>,
    //expr: exmex::FlatEx<Val<i64>, exmex::ValOpsFactory<i64>, exmex::ValMatcher>,
}

impl QuickExpression
{

 pub fn do_something(&self) {
     let big_num = 0xF1F2F3F4F5F6F7u64 as i64;
     let res = self.expr.eval(&[bin_num]);
     //...
 }

}

I need to work with f64 and i64:

let text = "2 * {random_value}";
let expr = exmex::parse_val::<i64, f64>(text.as_str());

let my_expr = QuickExpression{raw_text: text, expr: expr};
bertiqwerty commented 11 months ago

Hi @hanusek, you can use exmex::FlatExVal<i64, f64> as type in your struct.

bertiqwerty commented 11 months ago

If you have any open question, feel free to re-open.