Pattern binding the same variable to different types sharing a trait
问题 I have a question about pattern matching on values sharing some behaviour through a trait. I have an enum with two variants, each binding value of different types, where both types implement a trait. I'm trying to figure out whether it's possible to create a single pattern (of the E::VarA(x) | E::VarB(x) form) in which I bind both types to a single constant, provided I'm only interested in using the shared behaviour. An illustrative example: Playground: trait T { fn f(&self) -> usize; }