plantuml_server_client_rs/
format.rs1#[derive(Clone, Debug, PartialEq, Eq)]
3pub enum Format {
4 Png,
6 Svg,
8 Ascii,
10}
11
12impl From<&Format> for &'static str {
13 fn from(format: &Format) -> &'static str {
15 match format {
16 Format::Png => "png",
17 Format::Svg => "svg",
18 Format::Ascii => "txt",
19 }
20 }
21}
22
23impl std::fmt::Display for Format {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
26 let x: &str = self.into();
27 x.fmt(f)
28 }
29}
30
31impl std::str::FromStr for Format {
32 type Err = anyhow::Error;
33 fn from_str(s: &str) -> anyhow::Result<Self> {
35 match s.to_string().to_lowercase().as_str() {
36 "png" => Ok(Format::Png),
37 "svg" => Ok(Format::Svg),
38 "txt" => Ok(Format::Ascii),
39 _ => anyhow::bail!("unsupported format"),
40 }
41 }
42}