feat(layout): expose decoder layout metadata behind cargo feature#66
Conversation
|
Nice work on this — the API design is clean and the feature-gating approach is solid. Before we merge, could you share what your use case is for this? Are you building a formatter, linter, or some other tooling on top of toon-rust that needs the layout metadata? Just want to understand the motivation so we can make sure the API fits real-world needs. |
|
Thanks Shreyas! The motivation is schema validation — specifically, I'm working toward a "TOON Schema" sidecar (a small JSON Schema 2020-12 dialect with TOON-specific keywords) so tools can validate things like:
None of that is recoverable from the decoded The plan is roughly:
|
|
Hey @apardawala — thanks for the detailed explanation of your use case, the schema validation direction makes sense as a concept. Before we move forward with this, there's some important context we want to flag. @johannschopplich closed spec issues toon-format/spec#7 and toon-format/spec#17 with a clear position on keeping schema concerns separate from the core:
Your plan mentions filing a spec RFC as step 3, but that hasn't happened yet and there's no community discussion around "TOON Schema" as a concept. This PR adds layout tracking into the core decoder — even behind a feature flag, that's a meaningful addition to the core crate's responsibility, and we want to make sure the direction has buy-in before merging infrastructure for it. @johannschopplich — would appreciate your thoughts here. Specifically:
We've created an issue to track this: #69 Putting this on hold until we have clarity on the direction. The code itself is clean and well-designed — this is purely about whether it's the right home for it. |
|
@shreyasbhat0 Thanks for flagging, much appreciated. 🙂 Yes, TOON is a transport format in its core, that's why I've closed the schema approach in the past. Implementations shall follow the official spec – at the same time I'm open to experimentation. The format is not set in stone. If some kind of schema does improve the usefulness of TOON, I'm happy to reconsider. This repo can be a playground. From a SOC-first perspective, a separate crate would make sense. But that would bloat the package surface. I'm equally open to merging this behind a feature flag with a clear note that said schema feature is an independant development of this package. |
|
Thanks @johannschopplich — pushed f8e90b2 with the "experimental, independent of spec" note in four places: README cargo features, Also drafting an RFC on @shreyasbhat0 — does the wording in f8e90b2 address #69, or would you like changes? |
|
Thanks for the update @apardawala, and for adding the experimental disclaimers — that looks good. Before we can continue reviewing, this PR has merge conflicts that need to be resolved against A few code-level notes from an initial pass:
Will do a deeper review once the conflicts are resolved. The overall design and test coverage look solid. |
f8e90b2 to
400a1e7
Compare
|
Thanks @shreyas-ks — addressed all four points (rebased onto v0.4.6):
|
|
@apardawala can you please fix failing fmt CI |
400a1e7 to
8e3c7cc
Compare
Summary
Adds an opt-in
layoutcargo feature exposing structural metadata about how a TOON document was actually written on the wire — tabular vs. list vs. inline arrays, declared[N]lengths, declared field lists, and active delimiters. Useful for downstream tools (validators, linters, formatters) that need to reason about wire shape and not just the decoded value.API surface (additive only)
Layout entries are keyed by JSON Pointer (RFC 6901), with
""for the document root. All public types use#[non_exhaustive]so future additions don't break semver.Scope
Object key-order and key-folding metadata are intentionally deferred to a follow-up to keep this PR small.
FieldDescriptor::nestedis reserved for forward compatibility with proposals like spec RFC #46 (nested tabular headers) and is alwaysNonetoday.The interaction with
expand_pathsis documented ondecode_with_layout: pointers reflect pre-expansion structure.