vaidehijoshi / css-colors

A Rust converter for transforming CSS colors! 🎨
https://crates.io/crates/css-colors
ISC License
27 stars 9 forks source link

associated type `Alpha` must be specified #17

Open Sjord opened 4 years ago

Sjord commented 4 years ago

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 commented 4 years ago

@vaidehijoshi ?