Can traits be used on enum types?

Can traits be used on enum types?

Yes. In fact, you already have multiple traits defined for your enum; the traits Debug, Copy and Clone:

#[derive(Debug, Copy, Clone)]
pub enum SceneType

The problem is that you aren’t attempting to implement Playable for your enum, you are trying to implement it for one of the enum’s variants. Enum variants are not types.

As the error message tells you:

help: you can try using the variant's enum: `SceneType`
impl Playable for SceneType {
    fn play() {}
}

See also:

  • Can struct-like enums be used as types?
  • Is there a way to use existing structs as enum variants?

Leave a Comment

tech