1#[cfg(windows)]
15pub mod win;
16
17pub unsafe fn pwstr_to_string(ptr: *mut u16) -> String {
21 use std::slice::from_raw_parts;
22
23 let array: &[u16] = unsafe {
25 let len = (0_usize..)
26 .find(|&n| *ptr.add(n) == 0)
27 .expect("Couldn't find null terminator");
28 from_raw_parts(ptr, len)
29 };
30
31 String::from_utf16_lossy(array)
32}
33
34pub unsafe fn pstr_to_string(ptr: *mut i8) -> String {
38 use std::slice::from_raw_parts;
39
40 let array: &[u8] = unsafe {
42 let len = (0_usize..)
43 .find(|&n| *ptr.add(n) == 0)
44 .expect("Couldn't find null terminator");
45 from_raw_parts(ptr as *const u8, len)
46 };
47
48 String::from_utf8_lossy(array).to_string()
49}
50
51#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
56#[serde(from = "serde_json::Value")]
57#[serde(into = "serde_json::Value")]
58pub struct JsonValue(String);
59
60impl PartialEq for JsonValue {
61 fn eq(&self, other: &Self) -> bool {
62 let left: serde_json::Value = self.into();
63 let right: serde_json::Value = other.into();
64 left == right
65 }
66}
67
68impl Eq for JsonValue {}
69
70impl From<&serde_json::Value> for JsonValue {
71 fn from(value: &serde_json::Value) -> Self {
72 JsonValue(serde_json::to_string(value).unwrap())
73 }
74}
75
76impl From<serde_json::Value> for JsonValue {
77 fn from(value: serde_json::Value) -> Self {
78 (&value).into()
79 }
80}
81
82impl From<&JsonValue> for serde_json::Value {
83 fn from(value: &JsonValue) -> Self {
84 serde_json::from_str(&value.0).unwrap()
85 }
86}
87
88impl From<JsonValue> for serde_json::Value {
89 fn from(value: JsonValue) -> Self {
90 (&value).into()
91 }
92}
93
94impl Default for JsonValue {
95 fn default() -> Self {
96 serde_json::Value::default().into()
97 }
98}
99
100impl JsonValue {
101 pub fn into_serde_value(&self) -> serde_json::Value {
102 self.into()
103 }
104}
105
106#[derive(Debug, Clone)]
111pub struct JsonKeyValueMap(String);
112
113impl From<&serde_json::Map<String, serde_json::Value>> for JsonKeyValueMap {
114 fn from(value: &serde_json::Map<String, serde_json::Value>) -> Self {
115 JsonKeyValueMap(serde_json::to_string(value).unwrap())
116 }
117}
118
119impl From<serde_json::Map<String, serde_json::Value>> for JsonKeyValueMap {
120 fn from(value: serde_json::Map<String, serde_json::Value>) -> Self {
121 (&value).into()
122 }
123}
124
125impl From<&JsonKeyValueMap> for serde_json::Map<String, serde_json::Value> {
126 fn from(value: &JsonKeyValueMap) -> Self {
127 serde_json::from_str::<serde_json::Map<String, serde_json::Value>>(&value.0).unwrap()
128 }
129}
130
131impl From<JsonKeyValueMap> for serde_json::Map<String, serde_json::Value> {
132 fn from(value: JsonKeyValueMap) -> Self {
133 (&value).into()
134 }
135}
136
137impl Default for JsonKeyValueMap {
138 fn default() -> Self {
139 serde_json::Map::<String, serde_json::Value>::default().into()
140 }
141}
142
143impl PartialEq for JsonKeyValueMap {
144 fn eq(&self, other: &Self) -> bool {
145 let left: serde_json::Map<String, serde_json::Value> = self.into();
146 let right: serde_json::Map<String, serde_json::Value> = other.into();
147 left == right
148 }
149}
150
151impl Eq for JsonKeyValueMap {}
152
153impl JsonKeyValueMap {
154 pub fn into_serde_map(&self) -> serde_json::Map<String, serde_json::Value> {
155 self.into()
156 }
157}