MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / serialize

Function serialize

std/json/src/main/serializer.rs:40–54  ·  view source on GitHub ↗
(value: &Handle, opts: Options)

Source from the content-addressed store, hash-verified

38const MAX_DEPTH: usize = 200;
39
40pub fn serialize(value: &Handle, opts: Options) -> Result<String> {
41 // `cls` short-circuits the whole walk: instantiate and delegate to its `.encode(value)`.
42 if let Some(cls) = &opts.cls {
43 let encoder = cls.call("__call__", &[])?;
44 let result = encoder.call("encode", &[value.raw()])?;
45 return match decode(result.raw())? {
46 Value::Bytes(b) => String::from_utf8(b).map_err(|e| Error::Value(format!("cls.encode produced non-UTF-8: {}", e))),
47 _ => Err(Error::Type("cls.encode must return str".into())),
48 };
49 }
50 let mut out = String::new();
51 let mut ctx = SerCtx { opts: &opts, depth: 0 };
52 serialize_into(value, &mut out, &mut ctx, 0)?;
53 Ok(out)
54}
55
56fn serialize_into(value: &Handle, out: &mut String, ctx: &mut SerCtx, depth: usize) -> Result<()> {
57 let ty_handle = value.type_of()?;

Callers 1

dumpsFunction · 0.85

Calls 5

serialize_intoFunction · 0.85
decodeFunction · 0.50
ValueEnum · 0.50
callMethod · 0.45
rawMethod · 0.45

Tested by

no test coverage detected