(value: &Handle, out: &mut String, ctx: &mut SerCtx, depth: usize)
| 112 | } |
| 113 | |
| 114 | fn serialize_sequence(value: &Handle, out: &mut String, ctx: &mut SerCtx, depth: usize) -> Result<()> { |
| 115 | if ctx.opts.check_circular && depth >= MAX_DEPTH { |
| 116 | return Err(Error::Value("Circular reference detected".into())); |
| 117 | } |
| 118 | out.push('['); |
| 119 | let it = value.iter()?; |
| 120 | let n = it.len()?; |
| 121 | if n == 0 { |
| 122 | out.push(']'); |
| 123 | return Ok(()); |
| 124 | } |
| 125 | let indent_str = ctx.opts.indent.map(|n| " ".repeat(n.max(0) as usize)); |
| 126 | for i in 0..n { |
| 127 | let idx = encode(Value::Int(i as i128))?; |
| 128 | let item = it.get_item(&idx)?; |
| 129 | if i > 0 { out.push_str(&ctx.opts.item_sep); } |
| 130 | write_indent(out, indent_str.as_deref(), depth + 1); |
| 131 | serialize_into(&item, out, ctx, depth + 1)?; |
| 132 | } |
| 133 | write_indent(out, indent_str.as_deref(), depth); |
| 134 | out.push(']'); |
| 135 | Ok(()) |
| 136 | } |
| 137 | |
| 138 | fn serialize_object(value: &Handle, out: &mut String, ctx: &mut SerCtx, depth: usize) -> Result<()> { |
| 139 | if ctx.opts.check_circular && depth >= MAX_DEPTH { |
no test coverage detected