xavier_internal/serialize/
primitives.rs1use crate::serialize::macro_trait::XmlSerializable;
2
3fn tag_to_string<T>(obj: &T, tag_name: Option<&str>) -> String where T: ToString{
4 if let Some(tag_name) = tag_name {
5 format!("<{}>{}</{}>", tag_name, obj.to_string(), tag_name)
6 } else {
7 obj.to_string()
8 }
9}
10
11impl XmlSerializable for i8 {
12 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
13 tag_to_string(self, tag_name)
14 }
15}
16
17impl XmlSerializable for i16 {
18 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
19 tag_to_string(self, tag_name)
20 }
21}
22
23impl XmlSerializable for i32 {
24 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
25 tag_to_string(self, tag_name)
26 }
27}
28
29impl XmlSerializable for i64 {
30 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
31 tag_to_string(self, tag_name)
32 }
33}
34
35impl XmlSerializable for i128 {
36 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
37 tag_to_string(self, tag_name)
38 }
39}
40
41impl XmlSerializable for u8 {
42 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
43 tag_to_string(self, tag_name)
44 }
45}
46
47impl XmlSerializable for u16 {
48 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
49 tag_to_string(self, tag_name)
50 }
51}
52
53impl XmlSerializable for u32 {
54 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
55 tag_to_string(self, tag_name)
56 }
57}
58
59impl XmlSerializable for u64 {
60 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
61 tag_to_string(self, tag_name)
62 }
63}
64
65impl XmlSerializable for u128 {
66 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
67 tag_to_string(self, tag_name)
68 }
69}
70impl XmlSerializable for f32 {
71 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
72 tag_to_string(self, tag_name)
73 }
74}
75
76impl XmlSerializable for f64 {
77 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
78 tag_to_string(self, tag_name)
79 }
80}
81
82impl XmlSerializable for bool {
83 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
84 tag_to_string(self, tag_name)
85 }
86}
87
88impl XmlSerializable for String {
89 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
90 tag_to_string(self, tag_name)
91 }
92}
93
94impl XmlSerializable for isize {
95 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
96 tag_to_string(self, tag_name)
97 }
98}
99
100impl XmlSerializable for usize {
101 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
102 tag_to_string(self, tag_name)
103 }
104}
105
106impl XmlSerializable for char {
107 fn to_xml(&self, tag_name: Option<&str>, _: bool) -> String {
108 if let Some(tag_name) = tag_name {
109 format!("<{}>{}</{}>", tag_name, format!("{}", self), tag_name)
110 } else {
111 format!("{}", self)
112 }
113 }
114}
115
116