docx_rs/types/
character_spacing_values.rs

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