#[non_exhaustive]pub struct ModelSchema {
pub table: &'static str,
pub columns: &'static [ModelColumn],
pub primary_key: &'static str,
pub search_index: Option<&'static str>,
}Expand description
The full schema contract for one model.
Generated by #[derive(RustioModel)] in commit 2 and exposed via
rustio_core::contract::HasSchema (also commit 2). The validator
in commit 3 consumes a &'static ModelSchema and produces a
SchemaReport.
Lives entirely in static memory. Cloning copies the slice fat pointer, not the contents.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.table: &'static strSQL table name. Conventionally plural snake_case
(projects, invoices).
columns: &'static [ModelColumn]All columns in declaration order. Validator uses this both for forward checks (every Rust column must be in PG) and reverse checks (every PG column not in Rust → warning).
primary_key: &'static strName of the primary-key column. Conventionally "id". Must
match exactly one entry in columns with primary_key: true.
search_index: Option<&'static str>Meili index name when the model is searchable, None when
it isn’t. Conventionally equal to table.
Implementations§
Source§impl ModelSchema
impl ModelSchema
Sourcepub const fn new(
table: &'static str,
columns: &'static [ModelColumn],
primary_key: &'static str,
) -> Self
pub const fn new( table: &'static str, columns: &'static [ModelColumn], primary_key: &'static str, ) -> Self
Construct a schema from its required parts. search_index
defaults to None; opt in via Self::with_search_index.
const fn so the macro can emit
static SCHEMA: ModelSchema = ModelSchema::new(...) directly,
and so external code (tests, examples) can construct schemas
despite the #[non_exhaustive] attribute.
static COLS: &[ModelColumn] = &[
ModelColumn::new("id", "BIGSERIAL PRIMARY KEY", RustType::I64).primary_key(),
];
const POSTS: ModelSchema = ModelSchema::new("posts", COLS, "id");Sourcepub const fn with_search_index(self, index: &'static str) -> Self
pub const fn with_search_index(self, index: &'static str) -> Self
Set the Meili index name. Conventionally equal to table.
Setting this signals the model is searchable; the search
pipeline in commit 6 keys off this field.
Sourcepub fn column(&self, name: &str) -> Option<&ModelColumn>
pub fn column(&self, name: &str) -> Option<&ModelColumn>
Find a column by name. O(n) linear scan — column counts
are small (typically < 20 per model) and this is not on a
hot path.
Sourcepub fn searchable_columns(&self) -> impl Iterator<Item = &ModelColumn>
pub fn searchable_columns(&self) -> impl Iterator<Item = &ModelColumn>
All columns flagged as searchable. The macro layer in
commit 2 guarantees these are all RustType::String.
Trait Implementations§
Source§impl Clone for ModelSchema
impl Clone for ModelSchema
Source§fn clone(&self) -> ModelSchema
fn clone(&self) -> ModelSchema
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ModelSchema
impl RefUnwindSafe for ModelSchema
impl Send for ModelSchema
impl Sync for ModelSchema
impl Unpin for ModelSchema
impl UnsafeUnpin for ModelSchema
impl UnwindSafe for ModelSchema
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