about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-05-21 19:49:51 +0000
committerbors <bors@rust-lang.org>2022-05-21 19:49:51 +0000
commit9257f5aad02b65665a6e23e5b92938548302e129 (patch)
treeaf052cd62b50d1fb6a39b3146712cb5e2a5f09d1
parentbb4781aa277b6746e6f072252ddad95c59e94fd1 (diff)
parenta8acfa89864a4c1f479d81e3effa3a7101e7c39a (diff)
downloadrust-9257f5aad02b65665a6e23e5b92938548302e129.tar.gz
rust-9257f5aad02b65665a6e23e5b92938548302e129.zip
Auto merge of #94530 - tmiasko:alignment-impls, r=dtolnay
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<usize>,
    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.
-rw-r--r--library/core/src/fmt/mod.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index 700a78cac5a..dde9bc383d2 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -21,7 +21,7 @@ mod num;
 #[stable(feature = "fmt_flags_align", since = "1.28.0")]
 #[cfg_attr(not(test), rustc_diagnostic_item = "Alignment")]
 /// 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.