Include color structs (e.g White/Black) into an enum
Created by: lotabout
Current all color structs are independent and all implement trait termion::color::Color
. It had limitations however.
Example 1
Let's assume we want to store a color object that can be changed later, so we define it as
let c: Box<Color> = Box::new<color::White;>
However, color::Fg
and color::Bg
require an object that implements trait Color
. That means the stored trait object cannot be used with them.
println!("{}White", color::Fg(*c));
It won't work!
Example 2
Let's assume color::Bg
and color::Fg
works this time. Say we are implement some color scheme, so we have struct like:
pub struct ColorTheme {
highlighted: Box<Color>,
}
A common requirement is to allow a color theme to be cloned, so we modify the code as:
#[derive(clone)]
pub struct ColorTheme {
highlighted: Box<Color>,
}
It won't work because Box<Color>
is an trait object.
Proposal
- Perhaps we could require
Clone
forColor
. Liketrait Color: Clone
. - Implement
Color
forBox<Color>
. So that example 1 could work. - Or put all structs into an
enum
.