Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow set existing variable with another type #167

Open
unidevel opened this issue Feb 22, 2024 · 0 comments
Open

allow set existing variable with another type #167

unidevel opened this issue Feb 22, 2024 · 0 comments

Comments

@unidevel
Copy link

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?

@unidevel unidevel changed the title allow set existing variable to another type allow set existing variable with another type Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant