Expand description
Phase 14, commit 5 — bridge from ModelSchema to admin metadata.
This module is the framework’s first real consumer of the
Phase 14 schema contract. Given a &ModelSchema produced by
#[derive(RustioModel)], it emits the per-column admin
metadata required by the existing admin UI without a hand-
written AdminModel impl.
§What stays untouched
Existing manual admin paths (the #[derive(RustioAdmin)]
macro and projects that hand-build an AdminModel) are not
affected. This module is additive — it produces values
that consumers can plug into the existing AdminEntry
constructor; it never modifies, replaces, or shadows any
existing admin type.
§Mapping rules (Phase 14, commit 5 spec)
For each ModelColumn:
| Contract field | Bridge output |
|---|---|
name | AdminField.name (verbatim) |
admin_label | AdminField.label (fallback = name) |
admin_widget | BridgedField.widget (preserved through) |
flags.searchable | BridgedField.searchable |
flags.filterable | BridgedField.filterable |
flags.sortable | BridgedField.sortable |
flags.readonly | BridgedField.readonly + editable=!ro |
primary_key | BridgedField.primary_key |
AdminField (the existing type) only models editable. The
remaining flag bits and the widget hint live on
BridgedField — a side-channel struct so consumers (search
indexer, list/sort UI, future renderer changes) can read them
without breaking AdminField’s shape.
§Static lifetimes via Box::leak
AdminField requires &'static str and an &'static [AdminField] slice (the existing macro emits compile-time
constants). When bridging at runtime, we promote owned data
to static via Box::leak. This is a one-time setup cost
equivalent to a static: schemas are registered at process
startup and live for the program’s lifetime, so leaked memory
is never reclaimed but never grows either.
§No DB, no reflection, no new deps
Pure CPU. No async, no database access, no unsafe, no new
Cargo.toml entries.
Structs§
- Bridged
Field - One column in its bridge form: the existing
AdminField(consumed verbatim by the admin UI) plus the column-level flagsAdminFielddoesn’t model.
Functions§
- admin_
entry_ from_ schema - Build a fully-configured
AdminEntryfrom aModelSchema, without requiring anAdminModelimpl. The resulting entry’s CRUD goes throughSchemaOps; the field metadata comes fromadmin_fields_from_schema. - admin_
entry_ from_ type - Same as
admin_entry_from_schemabut takes the model type rather than a schema value. Convenience wrapper aroundT::SCHEMA. - admin_
fields_ from_ schema - Static-leaked
&'static [AdminField]for direct use asAdminEntry.fields. Equivalent to astaticarray — the memory is allocated once and lives the program’s lifetime. - bridged_
fields_ from_ schema - Bridge every column in declaration order. Order is
preserved 1:1 with
schema.columns— the admin UI lists columns in the order the model declared them, and skipping or reordering would silently change rendered forms. - field_
type_ for - Map a contract column’s
(RustType, nullable)pair to the admin’sFieldTypevocabulary. - label_
for - Resolved admin label.
- primary_
key_ column - The schema’s primary-key column, located by the
primary_key = trueflag. ReturnsNonewhen no column is flagged (a malformed schema; the validator in commit 3 surfaces this asWrongPrimaryKey).