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