From a8acfa89864a4c1f479d81e3effa3a7101e7c39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 2 Mar 2022 00:00:00 +0000 Subject: [PATCH] Implement Copy, Clone, PartialEq and Eq for core::fmt::Alignment Alignment is a fieldless exhaustive enum, so it is already possible to clone and compare it by matching, but it is inconvenient to do so. For example, if one would like to create a struct describing a formatter configuration and provide a clone implementation: ```rust pub struct Format { fill: char, width: Option, align: fmt::Alignment, } impl Clone for Format { fn clone(&self) -> Self { Format { align: match self.align { fmt::Alignment::Left => fmt::Alignment::Left, fmt::Alignment::Right => fmt::Alignment::Right, fmt::Alignment::Center => fmt::Alignment::Center, }, .. *self } } } ``` Derive Copy, Clone, PartialEq, and Eq for Alignment for convenience. --- library/core/src/fmt/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 90c5719f486cb..8df415f80c4f6 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -20,7 +20,7 @@ mod num; #[stable(feature = "fmt_flags_align", since = "1.28.0")] /// Possible alignments returned by `Formatter::align` -#[derive(Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum Alignment { #[stable(feature = "fmt_flags_align", since = "1.28.0")] /// Indication that contents should be left-aligned.