Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 152 forks source link

Fixed the `fmt` conflict caused by using `use std::fmt::Debug` #322

Closed disoul closed 10 months ago

disoul commented 11 months ago

use std::fmt::Debug; // <--- add this line, for example some people might wish to custom implement the Debug trait

#[derive(Eq, PartialEq, EnumString, Display, EnumCount, EnumDiscriminants, EnumIs)]
pub enum Color {
    /// Docs on red
    #[strum(to_string = "RedRed")]
    Red,
    #[strum(serialize = "b", to_string = "blue")]
    Blue { hue: usize },
    #[strum(serialize = "y", serialize = "yellow")]
    Yellow,
    #[strum(disabled)]
    Green(String),
}

impl Debug for Color {
    ...
}

This will cause the following error.

error[E0034]: multiple applicable items in scope
 --> strum_tests/src/lib.rs:5:44
  |
5 | #[derive(Debug, Eq, PartialEq, EnumString, Display, EnumCount, EnumDiscriminants, EnumIs)]
  |                                            ^^^^^^^ multiple `fmt` found
  |
  = note: candidate #1 is defined in an impl of the trait `Debug` for the type `str`
  = note: candidate #2 is defined in an impl of the trait `std::fmt::Display` for the type `str`
  = note: this error originates in the derive macro `Display` (in Nightly builds, run with -Z macro-backtrace for more info)
Peternator7 commented 10 months ago

Good catch; thanks for the fix