rof_rs/object_format/
mod.rs1use std::{
2 collections::HashMap,
3 fmt::Debug,
4 hash::{Hash, Hasher},
5};
6pub mod data_value;
7
8pub mod property;
9
10use self::property::property_type::PropertyType;
11
12pub trait DataValue: Debug {
13 fn serialize(
16 &self,
17 pretty_print: bool,
18 tab_index: usize,
19 ) -> (
20 PropertyType, String, );
23
24 fn deserialize(
25 serialized_type: &PropertyType,
26 serialized_value: &str,
27 ) -> Option<Box<dyn DataValue>>
28 where
29 Self: Sized;
30
31 fn get_type(&self) -> PropertyType {
34 self.serialize(false, 0).0
35 }
36
37 fn is_implicit(&self) -> bool {
38 self.get_type().is_implicit()
39 }
40
41 fn clone_data_value(&self) -> Box<dyn DataValue>;
44
45 fn as_vec(&self) -> Vec<Box<dyn DataValue>> {
48 self.as_tuple_structure()
49 }
50
51 fn as_bool(&self) -> bool {
52 self.as_vec().len() > 0 || self.as_usize() != 0
53 }
54
55 fn as_character(&self) -> char {
56 'a'
57 }
58
59 fn as_enum_structure(
60 &self,
61 ) -> (
62 String, Vec<Box<dyn DataValue>>, ) {
65 (String::new(), Vec::new())
66 }
67
68 fn as_hashmap(&self) -> HashMap<Box<dyn DataValue>, Box<dyn DataValue>> {
69 HashMap::new()
70 }
71
72 fn as_string(&self) -> String {
73 String::new()
74 }
75
76 fn as_struct_structure(&self) -> HashMap<String, Box<dyn DataValue>> {
77 HashMap::new()
78 }
79
80 fn as_tuple_structure(&self) -> Vec<Box<dyn DataValue>> {
81 Vec::new()
82 }
83
84 fn as_f32(&self) -> f32 {
87 0.
88 }
89
90 fn as_f64(&self) -> f64 {
91 0.
92 }
93
94 fn as_u8(&self) -> u8 {
97 0
98 }
99
100 fn as_i8(&self) -> i8 {
101 0
102 }
103
104 fn as_u16(&self) -> u16 {
105 0
106 }
107
108 fn as_i16(&self) -> i16 {
109 0
110 }
111
112 fn as_u32(&self) -> u32 {
113 0
114 }
115
116 fn as_i32(&self) -> i32 {
117 0
118 }
119
120 fn as_u64(&self) -> u64 {
121 0
122 }
123
124 fn as_i64(&self) -> i64 {
125 0
126 }
127
128 fn as_u128(&self) -> u128 {
129 0
130 }
131
132 fn as_i128(&self) -> i128 {
133 0
134 }
135
136 fn as_usize(&self) -> usize {
137 0
138 }
139
140 fn as_isize(&self) -> isize {
141 0
142 }
143}
144
145impl PartialEq for dyn DataValue {
146 fn eq(&self, other: &Self) -> bool {
147 self.serialize(false, 0) == other.serialize(false, 0)
148 }
149}
150
151impl Eq for dyn DataValue {}
152
153impl Hash for dyn DataValue {
154 fn hash<H: Hasher>(&self, state: &mut H) {
155 self.serialize(false, 0).1.hash(state)
156 }
157}
158
159pub mod ignore_str_split;
160pub mod rof;
161pub mod string_escaper;