Expand description
§schema-emit-runtime
What the Rust that schema-emit writes links: the Reason a failure has, the Report failures go to, Failures, which keeps the first of them, and Holds, which keeps only whether any came. Being no_std, with one dependency, pattern-emit’s search side, and no allocator of its own, it builds into whatever module or binary the emitted check lands in. The decode feature adds decode, which needs std: the seeds and writers that the Deserialize and Serialize impls schema-emit writes compose, and Unfit, naming where a decode fails and why, as a Why to match on. Each seed also reads the binary form by position (decode::binary), chosen by the format’s is_human_readable.
§Why
Emitted checks link this crate, not schema-emit, which depends on serde_json and the JSON Schema front end. This crate is no_std and depends only on pattern-emit’s search side (no parser), so a check’s module brings in none of that. Built for wasm32, a module with emitted checks has no imports, and the first model costs about 3.5 KB.
§Conventions
no_std, one dependency, bar thedecodefeature. New code usescoreonly, and adds no crate.Patternis pattern-emit’s, re-exported so emitted code names onlys::.- Never panics. Pure crates deny
unwrap,expect, indexing, and unchecked arithmetic in its lints. A panic there would take down the process. - Failures go to
Report::fail, with the path as a string literal and its list indices inat. A recursive model marks its steps back to itself,Value(.left|.right)*.n, andatleads with the repeat count, then each repeat’s step and indices (Reportgives the order).Failureprints the expanded path. Entries pastDEPTHread as 0. A new reason is a newReasonvariant with its name inReason::name. Those names are what the suite compares against each case’s expected failures, so renaming one changes the expected output. - Helpers. A check’s arithmetic too long to write inline goes here as a function with a unit test beside it, like
multiple_ofandchars. - Testing. Unit tests sit beside the code and run with
cargo nextest run -p schema-emit-runtime. schema-emit’s suite tests the emitted checks.
§Binary form
A format that is not human-readable gets a positional form, with no intermediate value:
- A model is its fields in order, an optional one an option, then its kept keys: a list of key and value, else their text, else nothing where the model strips them.
- A map is a list of key and value; a repeated key in text keeps its place and takes the later value.
- A timestamp is whole seconds then nanoseconds, a duration as chrono writes it, bytes raw.
- A tuple is an option per position, then the list of the rest.
- A union is its branch’s index, then the branch’s value.
- A value of any kind is the text of its JSON, the one text.
- A binary failure is
Why::Other, with a fixed reason.
§Failures
- A failure is an
Unfit, held in a slot of the thread while it crosses the deserializer.Unfit::raisefills the slot and returns a custom error of one fixed message; no failure becomes text or comes back from it. - Each level the error returns through takes the
Unfitfrom the slot, leads its path with its step, and raises it again. An error of the text or the deserializer passes through unchanged. decode::rootempties the slot on entry, and takes theUnfiton failure. It makes an error that isn’t a raised failure anUnfitthere, once, with a fixed reason, formatting no error.Unfit::from_jsonreads aserde_json::Errorby its category.- An embedder that fills a model through another deserializer calls
Unfit::raisedafter the fill fails, for the lastUnfitraised in the thread.
§Skips
- A bad optional value is absent, and the decode notes it as a skip: an
Unfitwith its full place.decode_<name>returns the value with itsSkips; aDeserializeused directly notes nothing. Skipskeeps the first 15 and counts the rest indropped.- A skip names its place, as a failure does: each part that returns leads the skips noted inside it with its step.
- A union keeps the skips of the branch it chooses and drops those of the branches it tries.
- JSON text and a
serde_json::Valueskip. A tree deserializer skips if it answers a newtype struct withvisit_newtype_struct. A streaming deserializer other than serde_json’s text can’t skip, and the binary form has no skips: the bad value fails the decode. decode::jsonreads the text without copying any value first, and reads it again only where an optional value failed.
Structs§
- Failure
- One failure, as
Failureskeeps it: up toDEPTHlist indices. - Failures
- The first
Nfailures, and how many more were dropped: a value’s failures are capped. - Holds
- Whether every check reported to it held: a branch of
anyOf,oneOf, orifover an object or a list checks into one, so its verdict is one condition. - Pattern
- One pattern’s table, checked once and kept.
- Trail
- The
atof a failure being built: up toDEPTHentries, a push past them dropped. - Under
- Keeps the first failure at or under one path, and ignores the rest.
- Unusable
- Why a pattern can’t answer: its table failed the load check, or a search gave up.
Enums§
- Reason
- Why a value fails its check.
Constants§
Traits§
- Report
- Where a check sends each failure.
Functions§
- chars
- Text length in Unicode scalar values, as JSON Schema counts it.
- multiple_
of - Whether
xis a whole multiple ofm, as JSON Schema’smultipleOfreads it: the quotient is an integer, and a quotient pastf64’s range is not. - under
- Whether
failed, a failure’s path with itsat, ispathor a field or item under it. Both keep[]as the template:pathA.xs[]holdsA.xs[].v.