#[derive(Visitor)]
Expand description
Creates a new trait for user code to implement
on the specified enum
. This trait requires
implementors to implement handlers for all the
specified variants in the given enum.
Examples
#[macro_use]
use roopes::prelude::*;
#[derive(Visitor)]
enum TestEnum
{
Integer
{
value: i32,
},
Nothing,
}
struct Implementor;
impl TestEnumVisitor for Implementor
{
fn visit_integer(
&self,
value: &i32,
)
{
println!("got {value}");
}
fn visit_nothing(&self)
{
println!("got Nothing");
}
}
let test_visitor = TestEnumAcceptor::new(Implementor);
test_visitor.accept(&TestEnum::Integer { value: 10 });
test_visitor.accept(&TestEnum::Nothing);