idiolect-records
Serde record types mirroring the dev.idiolect.* lexicon family.
Overview
Every record lexicon in lexicons/dev/idiolect/ has a corresponding
module here with a strongly-typed struct deserializable from the
lexicon's canonical JSON shape. Shared types (visibility, schema
references, lens references) live in common; NSID constants live
in nsid. The entire crate is generated by
idiolect-codegen and regenerated in CI —
the lexicons are the source of truth, these types are the derived
reflection.
AnyRecord is the runtime discriminated union across every shipped
record kind. decode_record(nsid, value) dispatches by nsid string
into the matching variant.
Usage
use ;
// Decode a record body whose nsid is only known at runtime.
let record: AnyRecord = decode_record?;
match record
// Or decode directly into a typed struct.
let e: Encounter = from_value?;
Every generated record type implements the Record trait, which
carries const NSID: &'static str and fn kind() for generic code:
use Record;
Minimally-valid record fixtures are available via
idiolect_records::examples:
use examples;
let e = encounter;
let json = ENCOUNTER_JSON;
Conventions
- Records:
#[serde(rename_all = "camelCase")]. - Enum variants:
#[serde(rename_all = "kebab-case")]. - Datetimes: RFC 3339
Strings (compared byte-wise for ordering; callers parse viatime::OffsetDateTimewhen they need arithmetic). - CID links:
{ "$link": "bafy..." }wrapper (common::CidLink). #[serde(skip_serializing_if = "Option::is_none")]on every optional field.
Related
idiolect-codegen— emits this crate.@idiolect-dev/schema— TypeScript twin, generated from the same lexicons.