MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / to_serde_value

Method to_serde_value

aiscript-vm/src/value.rs:328–357  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

326 }
327
328 pub fn to_serde_value(&self) -> serde_json::Value {
329 match self {
330 Value::Number(n) => (*n).into(),
331 Value::Boolean(b) => (*b).into(),
332 Value::String(str) => str.to_string().into(),
333 Value::IoString(str) => str.to_string().into(),
334 Value::List(list) => serde_json::Value::Array(
335 list.borrow()
336 .data
337 .iter()
338 .map(|v| v.to_serde_value())
339 .collect(),
340 ),
341 Value::Object(obj) => serde_json::Value::Object(
342 obj.borrow()
343 .fields
344 .iter()
345 .map(|(k, v)| (k.to_string(), v.to_serde_value()))
346 .collect(),
347 ),
348 Value::Instance(instance) => instance
349 .borrow()
350 .fields
351 .iter()
352 .map(|(k, v)| (k.to_string(), v.to_serde_value()))
353 .collect(),
354 Value::EnumVariant(variant) => variant.value.to_serde_value(),
355 _ => serde_json::Value::Null,
356 }
357 }
358}
359
360// Implementations for Enum and EnumVariant

Callers 2

fromMethod · 0.80
validate_argsMethod · 0.80

Calls 2

ObjectClass · 0.85
borrowMethod · 0.45

Tested by

no test coverage detected