Skip to main content

Module entry_builder

Module entry_builder 

Source
Expand description

Dynamic AdminEntry construction — 0.7.3.

The compile-time AdminEntry list is baked by #[derive(RustioAdmin)] and drives route registration — there is no way to register a GET/POST pair for a struct the binary doesn’t know about. But for everything that just reads the model shape (the dashboard alerts, the suggestion engine, the schema diff on the review page), the schema on disk is a better source of truth than the compiled &'static [AdminField] slice.

This module turns that observation into a concrete type. A DynamicAdminEntry is the same conceptual shape as an AdminEntry but with owned String names and an owned Vec<DynamicAdminField>. Renderers that currently iterate compile-time entries can iterate dynamic ones instead; the only thing they give up is &'static identity.

§Safety

  • field_type_from_str is total: an unknown string never panics, it falls back to FieldType::String (which the renderer shows as a plain-text input). The CHANGELOG bump rule means the planner + schema layers would catch unknown types much earlier, but the fallback here is the defence in depth.
  • entries_effective is deterministic: when the cache is warm, order follows schema.models; when it’s cold, order follows the compile-time slice. Neither path allocates randomness.

§What this module does NOT do

  • It does not register routes. Route registration still needs a real T: AdminModel because item.field_display(name) is trait-bound.
  • It does not mutate the schema cache. Reads only.

Structs§

DynamicAdminEntry
Same shape as AdminEntry but with owned strings, so a schema re-read can rebuild one without touching the compile-time slice.
DynamicAdminField
Same shape as AdminField but owned. Derived either from a &'static AdminField or from a crate::schema::SchemaField.

Functions§

build_admin_entries
Build a Vec<DynamicAdminEntry> from the schema on disk. Every model’s fields are projected from schema fields; unknown type strings fall back to FieldType::String (see field_type_from_str). Order follows schema.models.
entries_effective
Single source of truth for rendering-side admin entries.
field_type_from_str
Parse a schema-level type name ("i32", "DateTime", …) back into a FieldType. Unknown strings fall through to FieldType::String so the renderer shows a plain-text input instead of panicking — the 0.7.3 “render as PlainText” rule.