Expand description
The Schema model – Record/Scalar/Ref, per docs/design/model.md (issue
#6). Ported from ~/dev/omnist/omnist/schema.py.
- Record – a closed set of fields, each
(label, type, cardinality). Cardinality is the unordered number of times a label may appear. - Scalar – exactly one of seven predefined value types (
string,integer,number,boolean,date,time,datetime), optionally nullable. There is no user-declared value-domain composition (no union/enum/literal) – seedocs/design/model.md§2/§5 for why: a composable value-domain would make schema-directed deserialization ambiguous (a value could satisfy more than one candidate with no principled way to choose). - Ref – a pointer into the schema’s named environment (records only); enables reuse and recursion.
- Any (
FieldType::Any) – accepts every legal document value unchecked. Ported from Python’sAnyType/ANYsingleton, which has been fully implemented and shipped there since v0.5.0 – not a speculative or deferred feature (the separate, still-unresolved question is whetheranyshould be a permanent part of the spec long-term; that governance question is untouched by this port simply catching up to Python’s existing behavior, see omnist-rs issue #29).
A field’s type is a Ref, a Scalar, or Any. There are no inline
records and no separate array type – “array” is a field with
cardinality max > 1.
Validation ignores order (per docs/design/model.md §7).
§Temporal shape-check
is_iso_date, is_iso_time, and is_iso_datetime are the single
source of truth for “is this string shaped like (and a semantically
valid) date/time/datetime,” pub(crate) so a future materialize/
infer module can reuse the exact same check instead of writing a
second, independently-maintained copy (per the porting playbook’s
pitfall list). Each check is stricter than a bare shape regex: the regex
only rules out the wrong spelling (Python’s datetime.fromisoformat
is deliberately wider – it also accepts ISO-8601 basic format
(20240101), week dates, and other spellings this crate’s docs never
promise) – the calendar/clock fields are additionally range-checked
(e.g. a syntactically-shaped "2024-02-30" is still rejected).
Structs§
- Field
- One named, cardinality-bound field slot of a record:
labeloftype, occurring[min, max]times (max = Noneis unbounded). - Record
- A closed set of named fields (constrained by its child labels).
- Ref
- A reference to a named record in a
Schema’s environment. - Scalar
- One of the seven predefined value types, optionally nullable.
- Schema
- A schema: a root reference plus an environment of named records.
- Validation
Error - One validation failure: where, what, and a stable code.
- Validation
Result - The outcome of
Schema::validate: empty on success, one entry per problem found (validation collects every error, not just the first).
Enums§
- Error
Code - A stable machine-readable validation failure code, mirroring the Python
reference’s
Error.codevalues. - Error
Family - Which top-level operation produced an
ErrorCode–validateandmaterializeshare this oneErrorCode/ValidationResultmechanism (seeValidationResult::add’s doc comment), but omnist-spec §8.3.1 namespaces error codes per call-site family (validate.*vs.materialize.*), not per underlying check, so the family has to be threaded through at the point a code is stringified rather than baked intoErrorCodeitself. - Field
Type - A field’s type: a
Refto a named record, aScalar, orAny(accepts every legal document value – ported from Python’sAnyType/ANYsingleton, shipped there since v0.5.0).Anyis not aScalar(it has no kind and no nullable flag – null is already included) and not aRef(it names nothing), so it gets its own unit variant rather than being folded into either. - Resolved
- A resolved field type: a record (via a
Ref), a bareScalar, orAny. - Scalar
Kind - One of the seven predefined value kinds a
Scalarcan hold (spec §2.2).
Constants§
- BOOLEAN
- Non-nullable
booleanscalar constant (spec §2.2, §3). - DATE
- Non-nullable
datescalar constant (spec §2.2, §3). - DATETIME
- Non-nullable
datetimescalar constant (spec §2.2, §3). - INTEGER
- Non-nullable
integerscalar constant (spec §2.2, §3). - NUMBER
- Non-nullable
numberscalar constant (spec §2.2, §3). - STRING
- Non-nullable
stringscalar constant (spec §2.2, §3). - TIME
- Non-nullable
timescalar constant (spec §2.2, §3).
Functions§
- matches_
kind - Does
valuematch scalar kindkind? Mirrors Python’smatches_kind– validation only checks, it never converts (seedocs/design/model.md§10). - nullable
- A copy of
scalarthat also acceptsnull(the?form).