css-colors icon indicating copy to clipboard operation
css-colors copied to clipboard

associated type `Alpha` must be specified

Open Sjord opened this issue 5 years ago • 1 comments

When using css-colors, I would like to create a function that takes any color, whether it is RGB or HSL:

fn darken(c: Color) {
    c.darken(percent(10))
}

However, this doesn't work, because the trait Color has an Alpha type, which is not specified in this case. The compiler gives an error:

error[E0191]: the value of the associated type `Alpha` (from the trait `css_colors::Color`) must be specified
  --> src/main.rs:12:14
   |
12 | fn darken(c: Color) {
   |              ^^^^^ associated type `Alpha` must be specified

Is there any way around this? Should there be two traits, one for any color and one for colors that can be converted to alpha?

Sjord avatar Jun 20 '20 09:06 Sjord

@vaidehijoshi ?

Sjord avatar Jun 24 '20 06:06 Sjord