badge_maker/badge/
style.rs1use crate::badge::style::Style::*;
2use crate::error::Error;
3use crate::error::Error::BadStyleChoice;
4use std::fmt::{Display, Formatter};
5
6#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
8pub enum Style {
9 Flat,
10 Plastic,
11 FlatSquare,
12 }
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 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 }
39 )
40 }
41}