pub struct Schema {
pub version: u32,
pub rustio_version: String,
pub models: Vec<SchemaModel>,
}Expand description
Top-level schema document. Serialised as rustio.schema.json.
#[serde(deny_unknown_fields)] locks the wire format: a future
schema version adding a field will fail to load under the older
rustio-core unless the version number is bumped in lockstep. Combined
with SCHEMA_VERSION, this catches accidental silent drift.
Fields§
§version: u32§rustio_version: String§models: Vec<SchemaModel>Implementations§
Source§impl Schema
impl Schema
Sourcepub fn relation_for(&self, model: &str, field: &str) -> Option<&Relation>
pub fn relation_for(&self, model: &str, field: &str) -> Option<&Relation>
Look up the Relation descriptor attached to (model, field),
if the field carries one. Returns None if the model or field
doesn’t exist, or if the field has no relation metadata. A
schema without relations behaves identically to pre-0.8.0 —
this accessor just returns None everywhere.
Sourcepub fn incoming_relations(&self, model: &str) -> Vec<IncomingRelation>
pub fn incoming_relations(&self, model: &str) -> Vec<IncomingRelation>
Enumerate every belongs_to relation in the schema that points
at model — i.e. the has_many view. Order follows model
order, then field order inside the model. Empty when no field
in the schema references model. Deterministic.
Sourcepub fn from_admin(admin: &Admin) -> Self
pub fn from_admin(admin: &Admin) -> Self
Build a schema from an already-constructed Admin. This is the
single supported path — we don’t parse Rust sources or read the
DB, so whatever the admin is serving is exactly what the schema
describes.
Output is deterministic: models and fields are emitted in sorted order so two invocations on the same registry produce identical JSON bytes.
Sourcepub fn validate(&self) -> Result<(), SchemaError>
pub fn validate(&self) -> Result<(), SchemaError>
Check the schema for internal consistency. Every production writer should call this before persisting and every consumer (including the AI layer) should call it after loading. The error is the first problem found; fix and revalidate.
Sourcepub fn parse(json: &str) -> Result<Self, SchemaError>
pub fn parse(json: &str) -> Result<Self, SchemaError>
Parse + validate a schema document. Both deserialization failure
(unknown fields, wrong types, missing keys) and any semantic
problem surface as SchemaError. Safe default for anything
reading a rustio.schema.json off disk.
Sourcepub fn to_pretty_json(&self) -> Result<String, Error>
pub fn to_pretty_json(&self) -> Result<String, Error>
Serialise to pretty JSON with a trailing newline. We pretty-print on purpose: the file is meant to be read by humans during code review and by AI tools that benefit from stable line-level anchors.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Schema
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnsafeUnpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more