From f00b3bdcc051a8d3b547c95b32a54517e4d20e44 Mon Sep 17 00:00:00 2001 From: Mike Taghavi Date: Wed, 29 Apr 2026 22:29:22 +0200 Subject: [PATCH] Expose structural_indexes() accessor on Buffers Stage-1 already computes byte offsets of every JSON structural char. Today the result lives in a private field; downstream callers must either rerun stage-1 or unsafe-transmute the buffer to read it. Adds a public read-only accessor: pub fn structural_indexes(&self) -> &[u32] Zero alloc, zero copy. Slice valid until the next parse reusing the same Buffers. --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 5a3051ac..4a6f0953 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,6 +102,21 @@ impl Default for Buffers { } impl Buffers { + /// Borrow the byte offsets of every JSON structural character produced by + /// stage-1 SIMD scanning. Populated as a side effect of any parse path + /// that takes `&mut Buffers` (`to_tape_with_buffers`, + /// `Deserializer::from_slice_with_buffers`, etc.). + /// + /// The returned slice is valid until the next parse call that reuses + /// these buffers. Useful for downstream tooling that wants to align + /// its own column indices against simd-json's structural decisions + /// without running stage-1 a second time. + #[cfg_attr(not(feature = "no-inline"), inline)] + #[must_use] + pub fn structural_indexes(&self) -> &[u32] { + &self.structural_indexes + } + /// Create new buffer for input length. /// If this is too small a new buffer will be allocated, if needed during parsing. #[cfg_attr(not(feature = "no-inline"), inline)]