Skip to content

Commit

Permalink
Merge pull request #199 from djc/patch-1
Browse files Browse the repository at this point in the history
Add `Edition::as_str()` method
  • Loading branch information
oli-obk committed Aug 25, 2022
2 parents 76d9c22 + dd8011d commit 12c913f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,27 @@ pub enum Edition {
_E2030,
}

impl Edition {
/// Return the string representation of the edition
pub fn as_str(&self) -> &'static str {
use Edition::*;
match self {
E2015 => "2015",
E2018 => "2018",
E2021 => "2021",
_E2024 => "2024",
_E2027 => "2027",
_E2030 => "2030",
}
}
}

impl fmt::Display for Edition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}

impl Default for Edition {
fn default() -> Self {
Self::E2015
Expand Down

0 comments on commit 12c913f

Please sign in to comment.