Skip to content
Discussion options

You must be logged in to vote

You have multiple options: You could derive FromPyObject for your enum and consume it directly, e.g.

#[derive(FromPyObject)]
enum Value {
  String(String),
  Bool(bool),
}

#[pyfunction]
fn evaluate(&mut self, py: Python, ctx: HashMap<String, Value>) -> PyResult<bool> {
    let context = Context::default();

    for (key, value) in ctx {
        context.add_variable(key, value);
    }

    let value = self.program.execute(&ctx).unwrap();
        
    match value {
        Value::Bool(v) => Ok(v),
        _ => Ok(false),
    }
}

But you could also try to extract the types required, i.e. use the FromPyObject trait manually, e.g.

#[pyfunction]
fn evaluate(&mut self, py: Python, ctx: HashMap<S…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@inikolaev
Comment options

@adamreichold
Comment options

@adamreichold
Comment options

Answer selected by inikolaev
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants