]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Auto merge of #94530 - tmiasko:alignment-impls, r=dtolnay
authorbors <bors@rust-lang.org>
Sat, 21 May 2022 19:49:51 +0000 (19:49 +0000)
committerbors <bors@rust-lang.org>
Sat, 21 May 2022 19:49:51 +0000 (19:49 +0000)
commit9257f5aad02b65665a6e23e5b92938548302e129
treeaf052cd62b50d1fb6a39b3146712cb5e2a5f09d1
parentbb4781aa277b6746e6f072252ddad95c59e94fd1
parenta8acfa89864a4c1f479d81e3effa3a7101e7c39a
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.
library/core/src/fmt/mod.rs