-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: consistent naming for enum variants (#2339)
- Loading branch information
Showing
13 changed files
with
41 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
use std::str::FromStr; | ||
|
||
use anyhow::bail; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)] | ||
#[serde(try_from = "String")] | ||
#[serde(rename_all = "kebab-case")] | ||
pub enum PreviewWrap { | ||
No, | ||
Yes, | ||
} | ||
|
||
impl FromStr for PreviewWrap { | ||
type Err = anyhow::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok(match s { | ||
"no" => Self::No, | ||
"yes" => Self::Yes, | ||
_ => bail!("Invalid `wrap` value: {s}"), | ||
}) | ||
} | ||
} | ||
|
||
impl TryFrom<String> for PreviewWrap { | ||
type Error = anyhow::Error; | ||
|
||
fn try_from(value: String) -> Result<Self, Self::Error> { Self::from_str(&value) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,10 @@ | ||
use std::str::FromStr; | ||
|
||
use anyhow::anyhow; | ||
use serde::Deserialize; | ||
|
||
#[derive(Default, Clone, Copy, Debug, Deserialize)] | ||
#[serde(try_from = "String")] | ||
#[serde(rename_all = "kebab-case")] | ||
pub enum Priority { | ||
Low = 0, | ||
#[default] | ||
Normal = 1, | ||
High = 2, | ||
} | ||
|
||
impl FromStr for Priority { | ||
type Err = anyhow::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"low" => Ok(Self::Low), | ||
"normal" => Ok(Self::Normal), | ||
"high" => Ok(Self::High), | ||
_ => Err(anyhow!("Invalid priority: {s}")), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<String> for Priority { | ||
type Error = anyhow::Error; | ||
|
||
fn try_from(s: String) -> Result<Self, Self::Error> { Self::from_str(&s) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,10 @@ | ||
use std::str::FromStr; | ||
|
||
use anyhow::bail; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] | ||
#[serde(try_from = "String")] | ||
#[serde(rename_all = "kebab-case")] | ||
pub enum SortBy { | ||
#[default] | ||
None, | ||
Key, | ||
Desc, | ||
} | ||
|
||
impl FromStr for SortBy { | ||
type Err = anyhow::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok(match s { | ||
"none" => Self::None, | ||
"key" => Self::Key, | ||
"desc" => Self::Desc, | ||
_ => bail!("Invalid `sort_by` value: {s}"), | ||
}) | ||
} | ||
} | ||
|
||
impl TryFrom<String> for SortBy { | ||
type Error = anyhow::Error; | ||
|
||
fn try_from(value: String) -> Result<Self, Self::Error> { Self::from_str(&value) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.