Skip to content

Commit a8acfa8

Browse files
committed
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.
1 parent 9fcbc32 commit a8acfa8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/core/src/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod num;
2020

2121
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
2222
/// Possible alignments returned by `Formatter::align`
23-
#[derive(Debug)]
23+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
2424
pub enum Alignment {
2525
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
2626
/// Indication that contents should be left-aligned.

0 commit comments

Comments
 (0)