I would like to have multiple, distinct structs which implement canvas::Program where Message is a different type for each for modularity. If I try to actually create a canvas from these structs in the main application’s view call based off of a condition, I get an error because Message is not the same type as the returned Message from the main application’s code call. This happens all over the place for other widgets like buttons where you just map the message to a wrapper enum variant, but I can’t find a mechanism for doing the same with a canvas. Is it possible to do that?
Wrap the different types of messages in a single enum
#[derive(Clone, Debug)]
pub enum Message {
Foo(foo::Message),
Bar(bar::Message),
}
// foo.rs
#[derive(Clone, Debug)]
pub enum Message {
Fizz,
Buzz
}
// bar.rs
#[derive(Clone, Debug)]
pub enum Message {
Frobnicate(String),
ShaveYak(usize)
}
Use .map()
to compose the messages as described in the pocket guide here: