about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2022-03-02 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2022-03-04 23:06:31 +0100
commita8acfa89864a4c1f479d81e3effa3a7101e7c39a (patch)
treefe69d05e5e754f9a39e8fb9c6a3ae551aa4a740a /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parent9fcbc32053d5084d1de79bd484de82474cdae427 (diff)
downloadrust-a8acfa89864a4c1f479d81e3effa3a7101e7c39a.tar.gz
rust-a8acfa89864a4c1f479d81e3effa3a7101e7c39a.zip
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.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions