MCPcopy Create free account
hub / github.com/hashintel/hash / serialize

Method serialize

libs/@local/hashql/eval/src/orchestrator/codec/encode/mod.rs:121–175  ·  view source on GitHub ↗
(&self, serializer: S)

Source from the content-addressed store, hash-verified

119
120impl<A: Allocator> Serialize for Serde<&Value<'_, A>> {
121 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
122 where
123 S: serde::Serializer,
124 {
125 match &self.0 {
126 Value::Unit => serializer.serialize_unit(),
127 Value::Integer(int) => {
128 if let Some(bool) = int.as_bool() {
129 serializer.serialize_bool(bool)
130 } else {
131 serializer.serialize_i128(int.as_int())
132 }
133 }
134 Value::Number(num) => serializer.serialize_f64(num.as_f64()),
135 Value::String(str) => serializer.serialize_str(str.as_str()),
136 Value::Pointer(_) => Err(serde::ser::Error::custom("pointer value not supported")),
137 Value::Opaque(opaque) => Self(opaque.value()).serialize(serializer),
138 Value::Struct(r#struct) => {
139 let mut inner = serializer.serialize_map(Some(r#struct.len()))?;
140
141 for (field, value) in r#struct.fields().iter().zip(r#struct.values()) {
142 inner.serialize_entry(&field.as_str(), &Self(value))?;
143 }
144
145 inner.end()
146 }
147 Value::Tuple(tuple) => {
148 let mut inner = serializer.serialize_seq(Some(tuple.len().get()))?;
149
150 for value in tuple.values() {
151 inner.serialize_element(&Self(value))?;
152 }
153
154 inner.end()
155 }
156 Value::List(list) => {
157 let mut inner = serializer.serialize_seq(Some(list.len()))?;
158
159 for value in list.iter() {
160 inner.serialize_element(&Self(value))?;
161 }
162
163 inner.end()
164 }
165 Value::Dict(dict) => {
166 let mut inner = serializer.serialize_map(Some(dict.len()))?;
167
168 for (key, value) in dict.iter() {
169 inner.serialize_entry(&Self(key), &Self(value))?;
170 }
171
172 inner.end()
173 }
174 }
175 }
176}
177
178/// Serializes a runtime [`Value`] to a JSON [`RawValue`] suitable for use as

Callers

nothing calls this directly

Calls 13

ErrInterface · 0.85
as_boolMethod · 0.80
zipMethod · 0.80
fieldsMethod · 0.80
getMethod · 0.65
as_intMethod · 0.45
as_f64Method · 0.45
as_strMethod · 0.45
valueMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected