for
struct State<T> { state: T }
with possible states struct A { id: Uuid }
struct B { id: Uuid }
use a trait trait HasId {
fn id_mut(&mut self) -> &mut Uuid;
}
now you can impl over both A and B impl<T: HasId> for State<T> {
fn new_id(&mut self) { *self.state.id_mut() = Uuid::new_v4() }
}
simplistic example but enough to communicate the idea hopefully.generally, macros makes this kind of thing ergonomic so you can generate the trait implementations and so on. otherwise it's a lot of typing.
don't understand what you mean about making callbacks to other APIs during transitions.