Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Copy, Clone, PartialEq and Eq for core::fmt::Alignment #94530

Merged
merged 1 commit into from
May 21, 2022

Commits on Mar 4, 2022

  1. 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.
    tmiasko committed Mar 4, 2022
    Configuration menu
    Copy the full SHA
    a8acfa8 View commit details
    Browse the repository at this point in the history