Skip to content

associated type Alpha must be specified #17

@Sjord

Description

@Sjord

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions