badge_maker/badge/
style.rs

1use crate::badge::style::Style::*;
2use crate::error::Error;
3use crate::error::Error::BadStyleChoice;
4use std::fmt::{Display, Formatter};
5
6/// Used to define the style of a badge. Used in [BadgeBuilder.style()](crate::badge::BadgeBuilder)
7#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
8pub enum Style {
9    Flat,
10    Plastic,
11    FlatSquare,
12    // ForTheBadge,
13    // Social,
14}
15
16pub fn parse_style(s: &str) -> Result<Style, Error> {
17    match s {
18        "flat" => Ok(Flat),
19        "plastic" => Ok(Plastic),
20        "flatsquare" => Ok(FlatSquare),
21        // "forthebadge" => Ok(ForTheBadge),
22        // "social" => Ok(Social),
23        choice => Err(BadStyleChoice(choice.to_string())),
24    }
25}
26
27impl Display for Style {
28    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29        write!(
30            f,
31            "{}",
32            match self {
33                Flat => "flat",
34                Plastic => "plastic",
35                FlatSquare => "flatsquare",
36                // ForTheBadge => "forthebadge",
37                // Social => "social",
38            }
39        )
40    }
41}