I'm trying to design a system but I'm having trouble making it fit into Rust's type system.
My library involves multiple backends which support multiple widgets. To do this, I want to have a Backend trait, and a Widget<B: Backend> trait. So far so good. But then, suppose I have a particular widget called Textbox. I would like its implementation for BackendA to have a different data structure than its implementation for BackendB. Here's where I run into problems:
If I have an enum of different backend impls of Textbox, then I wouldn't be able to create a new Backend in another crate and have it still work.
If I have the widget trait just point to the backend-specific type (e.g TextboxForBackendA), then I'd have to enumerate all the possible widgets I could have in the widget trait.
Your second code sample is closer to what I want, but that creates the problem of the Backend now having to enumerate all widget types again. I need Backends and Widgets to be able to be created arbitrarily and still fit into the system.
Thanks, this really helps! Although this complicates things it lets me represent the concepts I want. I'll probably eventually use some macros to clean it up.