In a Rust program, I have a use case where I want to print either a number, or a pipe-separated vector of numbers, thus this simple wrapper enum:
pub enum OneOrMore<T> { One(T), More(Vec<T>) } which works fine. But then I wanted to move the format logic into the OneOrMore type, so I tried:
impl<T: Show> Show for OneOrMore<T> { fn fmt(&self, f: &mut Formatter) -> Result { match self { One(x) => x.fmt(f), More(xs) => /* vec_join(xs, "|") or whatever */, } } } Since the impl is parameterized, it's expecting a One<T> but my code is describing a One<_>. Problem is I can't figure out where to put the type parameter inside the match arms. The syntax guide doesn't give an example of matching on parameterized types, fmt itself doesn't accept a type parameter, and all my blind guesses (One(x: T), One<T>(x), etc) aren't valid Rust. Any ideas where I should indicate the type of the match arms?