docx_reader/types/
height_rule.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use serde::Serialize;
use std::fmt;
use std::str::FromStr;

use super::errors;

#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum HeightRule {
	Auto,
	AtLeast,
	Exact,
}

impl Default for HeightRule {
	fn default() -> Self {
		Self::AtLeast
	}
}

impl fmt::Display for HeightRule {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		match *self {
			HeightRule::Auto => write!(f, "auto"),
			HeightRule::AtLeast => write!(f, "atLeast"),
			HeightRule::Exact => write!(f, "exact"),
		}
	}
}

impl FromStr for HeightRule {
	type Err = errors::TypeError;
	fn from_str(s: &str) -> Result<Self, Self::Err> {
		match s {
			"auto" => Ok(HeightRule::Auto),
			"atLeast" => Ok(HeightRule::AtLeast),
			"exact" => Ok(HeightRule::Exact),
			_ => Ok(HeightRule::AtLeast),
		}
	}
}