Derive Macro rusteval::Interactive
source · #[derive(Interactive)]
Expand description
Gives interactive access to a structs fields.
What it does:
#[derive(Interactive)]
struct Struct {
field1: u32,
field2: u32,
}
Expands to something like:
impl Interactive for Struct {
fn get_field<'a>(&'a self, field_name: &'a str) -> Result<'_, &dyn Interactive> {
match field_name {
"field1" => self.field1.try_as_interactive(),
"field2" => self.field2.try_as_interactive(),
_ => Err(FieldNotFound {
type_name: "Struct",
field_name,
}),
}
}
fn get_field_mut<'a>(&'a mut self, field_name: &'a str) -> Result<'_, &mut dyn Interactive> {
/* ... */
}
fn eval_field(&self, field_name: &str, f: &mut dyn FnMut(Result<'_, &dyn Debug>)) {
match field_name {
"field1" => f(self.field1.try_as_debug()),
/* ... */
}
}
fn get_all_field_names(&self) -> &'static [&'static str] {
&["field1", "field2"]
}
}