Rust

Rust

Made by DeepSource

Found enum variants with similar prefixes or suffixes RS-C1003

Anti-pattern
Minor

Enumeration variants with the same prefix or suffix as the enumeration name are repetitive. Variants should describe themselves, and not include the name of the parent enum in their names.

Restrict the names of enumeration variants to avoid repetition. Repetitive names encourage glob exports which may cause namespace overlaps.

Bad practice

enum Brush {
    LineBrush,
    CircleBrush,
    SelectBrush
}

// this nomenclature encourages glob exports:
use Brush::*;

let x = LineBrush;

match x {
    LineBrush => { }
    CircleBrush => { }
    _ => { }
}

Recommended

enum Brush {
    Line,
    Circle,
    Select
}

// equally explicit, but more idiomatic:
let x = Brush::Line;

match x {
    Brush::Line => { }
    Brush::Circle => { }
    _ => { }
}