plantuml_server_client_rs/
format.rs

1/// A representation of output format of PlantUML Server.
2#[derive(Clone, Debug, PartialEq, Eq)]
3pub enum Format {
4    /// PNG file
5    Png,
6    /// SVG XML file
7    Svg,
8    /// ASCII Art representation
9    Ascii,
10}
11
12impl From<&Format> for &'static str {
13    /// Converts to URL path parts or extension
14    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    /// Converts to URL path parts or extension
25    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    /// Converts frin URL path parts or extension
34    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}