I have created an enum to represent a set of built in types and I am trying to implement fmt::Display by using the existing implementations, however the code seems very repetitive especially as the list of types grows. Is there any cleaner way to achieve this by calling the function once?
pub enum NodeVal {
I8(i8),
I16(i16),
I32(i32),
}
impl fmt::Display for NodeVal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
NodeVal::I8(v) => ::std::fmt::Display::fmt(&v, f),
NodeVal::I16(v) => ::std::fmt::Display::fmt(&v, f),
NodeVal::I32(v) => ::std::fmt::Display::fmt(&v, f)
}
}
}