Skip to content

allow set existing variable with another type #167

@unidevel

Description

@unidevel

I'm using this to eval expr for a table. I want to set the current value as "$$", but the types of columns are different, when I use set_value from the context, it give error like Err(ExpectedInt { actual: String("test") }) when I try to set a string to an existing variable with value of int.

The test code is:

use evalexpr::{eval_with_context, ContextWithMutableVariables, HashMapContext, Value};

fn main() {
    let mut ctx = HashMapContext::new();
    let r1 = ctx.set_value("$$".into(), Value::from(123));
    let r2 = ctx.set_value("$$".into(), Value::from("test"));
    let r = eval_with_context("$$+1", &ctx);
    println!("result: {:?}, {:?}, {:?}", r1, r2, r);
}

Can you add a function to clear the variable or allow set_value with new type?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions