isbnlib/enums/
toc_enum.rs1use serde::{Deserialize, Serialize};
2use serde_json;
3
4use crate::jsonb::edition_toc::EditionToC;
5
6#[derive(
7Serialize,
8Deserialize,
9Debug,
10Clone,
11PartialEq,
12)]
13#[serde(untagged)]
14pub enum ToCEnum {
15 String(String),
16 ToC(EditionToC)
17}
18
19impl ToCEnum {
20 pub fn to_json(self) -> serde_json::Value {
21 match self {
22 ToCEnum::String(string) => {
23 serde_json::json!({
24 "String": string
25 })
26 }
27 ToCEnum::ToC(content) => {
28 let level = content.level.unwrap_or(0);
29 let title = content.title.unwrap_or(String::new());
30 let class = content.class.unwrap_or(String::new());
31
32 serde_json::json!({
33 "level": level,
34 "title": title,
35 "class": class
36 })
37 }
38 }
39 }
40}