docx_rs/types/
height_rule.rs

1use std::fmt;
2#[cfg(feature = "wasm")]
3use wasm_bindgen::prelude::*;
4
5use serde::Serialize;
6
7use super::errors;
8use std::str::FromStr;
9
10#[cfg_attr(feature = "wasm", wasm_bindgen)]
11#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
12#[serde(rename_all = "camelCase")]
13pub enum HeightRule {
14    Auto,
15    AtLeast,
16    Exact,
17}
18
19impl Default for HeightRule {
20    fn default() -> Self {
21        Self::AtLeast
22    }
23}
24
25impl fmt::Display for HeightRule {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        match *self {
28            HeightRule::Auto => write!(f, "auto"),
29            HeightRule::AtLeast => write!(f, "atLeast"),
30            HeightRule::Exact => write!(f, "exact"),
31        }
32    }
33}
34
35impl FromStr for HeightRule {
36    type Err = errors::TypeError;
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        match s {
39            "auto" => Ok(HeightRule::Auto),
40            "atLeast" => Ok(HeightRule::AtLeast),
41            "exact" => Ok(HeightRule::Exact),
42            _ => Ok(HeightRule::AtLeast),
43        }
44    }
45}