docx_reader/types/
width_type.rs

1use serde::Serialize;
2use std::fmt;
3use std::str::FromStr;
4
5use super::errors;
6
7#[derive(Copy, Clone, Debug, PartialEq, Serialize)]
8#[serde(rename_all = "camelCase")]
9pub enum WidthType {
10	Dxa,
11	Auto,
12	Pct,
13	Nil,
14	Unsupported,
15}
16
17impl fmt::Display for WidthType {
18	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19		match *self {
20			WidthType::Dxa => write!(f, "dxa"),
21			WidthType::Auto => write!(f, "auto"),
22			WidthType::Pct => write!(f, "pct"),
23			WidthType::Nil => write!(f, "nil"),
24			WidthType::Unsupported => write!(f, "unsupported"),
25		}
26	}
27}
28
29impl FromStr for WidthType {
30	type Err = errors::TypeError;
31	fn from_str(s: &str) -> Result<Self, Self::Err> {
32		// https://github.com/bokuweb/docx-rs/issues/451
33		match s {
34			"DXA" | "dxa" => Ok(WidthType::Dxa),
35			"Auto" | "auto" => Ok(WidthType::Auto),
36			"Pct" | "pct" => Ok(WidthType::Pct),
37			"Nil" | "nil" => Ok(WidthType::Nil),
38			_ => Ok(WidthType::Unsupported),
39		}
40	}
41}