use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Preset {
#[default]
Comments,
ProductReview,
LaunchThread,
}
impl Preset {
pub const NAMES: [&'static str; 3] = ["comments", "product-review", "launch-thread"];
pub fn name(self) -> &'static str {
match self {
Preset::Comments => "comments",
Preset::ProductReview => "product-review",
Preset::LaunchThread => "launch-thread",
}
}
pub fn setting(self) -> &'static str {
match self {
Preset::Comments => "a comment under a post",
Preset::ProductReview => "a user review of a product",
Preset::LaunchThread => "a comment in a product launch thread",
}
}
pub fn stock_phrases(self) -> &'static [&'static str] {
match self {
Preset::Comments => &[
"great post",
"nice post",
"thanks for sharing",
"great read",
],
Preset::ProductReview => &[
"great product",
"love it",
"highly recommend",
"five stars",
"works great",
"best app ever",
],
Preset::LaunchThread => &[
"congrats on the launch",
"congrats on launching",
"happy launch day",
"good luck with the launch",
"upvoted",
"great launch",
],
}
}
}
impl FromStr for Preset {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"comments" => Ok(Preset::Comments),
"product-review" => Ok(Preset::ProductReview),
"launch-thread" => Ok(Preset::LaunchThread),
other => Err(format!(
"unknown preset '{other}' (expected one of: {})",
Preset::NAMES.join(", ")
)),
}
}
}