I have two enumerations, NormalColour and BoldColour , both of which implement the Colour trait. They contain Blue , BoldGreen , etc.
I would like to return the values ββof both of these types from the same function, treating them as if they were just a Colour value, calling the paint function for the result, but I cannot find a way to force Rust complier to do this for me. I would like to write something like this:
pub trait Colour { fn paint(&self, input: &str) -> String; } fn file_colour(stat: &io::FileStat) -> Colour { if stat.kind == io::TypeDirectory { Blue } else if stat.perm & io::UserExecute == io::UserExecute { BoldGreen } else { White } }
What type should I make the function return to work?
In the end, I want to make more types that implement Colour , so I'm not interested in just turning two enumerations into one big jumper.
Ben s source share