rof_rs/object_format/data_value/
bool.rs1use crate::object_format::{property::property_type::PropertyType, DataValue};
2
3#[derive(Debug)]
6pub struct DataValueBool {
7 inner: bool,
8}
9
10impl DataValueBool {
11 pub fn new(inner_value: bool) -> Self {
12 Self { inner: inner_value }
13 }
14}
15
16impl DataValue for DataValueBool {
17 fn serialize(&self, _: bool, _: usize) -> (PropertyType, String) {
18 (
19 PropertyType::simple(String::from("bool")),
20 match self.inner {
21 true => String::from("true"),
22 false => String::from("false"),
23 },
24 )
25 }
26
27 fn deserialize(
28 serialized_type: &crate::object_format::property::property_type::PropertyType,
29 serialized_value: &str,
30 ) -> Option<Box<dyn DataValue>>
31 where
32 Self: Sized,
33 {
34 if serialized_type.get_base_type() != "" && serialized_type.get_base_type() != "bool"
35 || serialized_type.sub_types_included()
36 {
37 return None;
38 }
39
40 match serialized_value {
41 "true" => Some(Box::new(Self::new(true))),
42 "false" => Some(Box::new(Self::new(false))),
43 _ => None,
44 }
45 }
46
47 fn clone_data_value(&self) -> Box<dyn DataValue> {
48 Box::new(Self::new(self.inner))
49 }
50
51 fn as_bool(&self) -> bool {
52 self.inner
53 }
54}