Rust 中的简单枚举应该派生出哪些特征?

What traits should simple enums in Rust derive?

我有很多这样的枚举,它们只有标签——没有任何构造函数参数:

pub enum VarRec {
    Variant,
    Record,
}

我目前正在推导它们具有这些特征:

#[derive(Debug, PartialEq, Eq, Copy, Clone, Ord, PartialOrd, Hash)]

我希望他们可以实现最大数量的特征,因为枚举非常简单,我不希望他们因为缺少特征实现而失去任何能力。还有什么要添加到派生列表中的吗?

可以在 Rust API Guidelines. You've got most of the common traits they recommend, but you may also want to add Display and possibly Default if there's one variant you think of as more basic. The derive_more crate 找到一个很好的总结,可以帮助顺利实施 Display

那里还有很多建议,所以您应该看看是否有适合您的具体情况的建议。