Hello.
I need to get the name of an enum::struct instance.
pub enum Node {
IntNode {value: i32},
FloatNode {value: f32}
}
let e = Node::IntNode {value: 100};
let name = somefunctionname(e); // Something like `getStructName(e)`
name // Should return a String or &str with the value `IntNode`
Then I need to get a method by that string.
impl Interpreter {
fn visit(&mut self, funcname: String) {
let funcname = format!('visit_{}', funcname);
let method = somefunctionname(funcname); // Something like `getMethod(funcname, self)`
method(); // If funcname is `visit_IntNode` then this is equivalent to `self.visit_IntNode();`
}
fn visit_IntNode(&mut self) {}
}
If one of these is not possible, please let me know of a good alternative.