#[non_exhaustive]pub struct ModelColumn {
pub name: &'static str,
pub sql_decl: &'static str,
pub rust_type: RustType,
pub nullable: bool,
pub primary_key: bool,
pub flags: SchemaFlags,
pub admin_label: Option<&'static str>,
pub admin_widget: Option<&'static str>,
}Expand description
One column in a model’s contract.
All fields are &'static references because the contract is built
at compile time by #[derive(RustioModel)] (commit 2) and lives
in static memory. No allocations on the hot path.
#[non_exhaustive] so future fields (e.g. references for FKs,
default for column defaults) can be added without breaking.
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.name: &'static strColumn name as it appears in SQL.
sql_decl: &'static strVerbatim DDL fragment from the operator’s
#[rustio(sql = "...")] attribute. The validator parses this
when comparing against information_schema.columns. Examples:
"BIGSERIAL PRIMARY KEY", "TEXT NOT NULL",
"NUMERIC(12,2) NOT NULL DEFAULT 0".
rust_type: RustTypeRust type kind. The compatibility check goes through
RustType::is_compatible_with.
nullable: boolWhether the Rust field is Option<T>. When true, the
validator expects PG to allow NULL on this column; mismatch
is a validator error.
primary_key: boolWhether this column is the table’s primary key. Exactly one
column per ModelSchema should set this to true. Validation
of that invariant is the validator’s job (commit 3).
flags: SchemaFlagsAdmin / search flags.
admin_label: Option<&'static str>Optional admin display label override. None means use the
humanised column name ("full_name" → "Full name").
admin_widget: Option<&'static str>Optional admin form widget hint ("textarea", "email",
"tel", …). None means use the default for the
RustType — <input type="text"> for String,
<input type="number"> for I64, etc.
Implementations§
Source§impl ModelColumn
impl ModelColumn
Sourcepub const fn new(
name: &'static str,
sql_decl: &'static str,
rust_type: RustType,
) -> Self
pub const fn new( name: &'static str, sql_decl: &'static str, rust_type: RustType, ) -> Self
Minimal column constructor — name, SQL DDL, Rust type. All
flags default to false / None. Builder-style setters
below opt into the rest.
const fn so the macro in commit 2 can use this directly
inside static SCHEMA: ModelSchema = ... initialisers,
and so external callers (tests, the future
examples/freelance/ crate) can construct columns
despite the #[non_exhaustive] attribute.
const ID: ModelColumn =
ModelColumn::new("id", "BIGSERIAL PRIMARY KEY", RustType::I64)
.primary_key();Sourcepub const fn nullable(self) -> Self
pub const fn nullable(self) -> Self
Mark this column as nullable (the Rust field is Option<T>).
The validator will require PG to allow NULL on the column.
Sourcepub const fn primary_key(self) -> Self
pub const fn primary_key(self) -> Self
Mark this column as the table’s primary key. Exactly one
column per ModelSchema should set this. The validator
checks the invariant in commit 3.
Sourcepub const fn with_flags(self, flags: SchemaFlags) -> Self
pub const fn with_flags(self, flags: SchemaFlags) -> Self
Replace the column’s flags wholesale. Pair with
SchemaFlags::searchable() / SchemaFlags::empty() /
a struct literal (within the crate).
Sourcepub const fn with_label(self, label: &'static str) -> Self
pub const fn with_label(self, label: &'static str) -> Self
Override the admin display label. None (the default) means
the chrome humanises the column name (full_name →
Full name).
Sourcepub const fn with_widget(self, widget: &'static str) -> Self
pub const fn with_widget(self, widget: &'static str) -> Self
Override the admin form widget. Useful for upgrading a
String column to <textarea> or to a typed input
("email", "tel").
Trait Implementations§
Source§impl Clone for ModelColumn
impl Clone for ModelColumn
Source§fn clone(&self) -> ModelColumn
fn clone(&self) -> ModelColumn
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 ModelColumn
impl RefUnwindSafe for ModelColumn
impl Send for ModelColumn
impl Sync for ModelColumn
impl Unpin for ModelColumn
impl UnsafeUnpin for ModelColumn
impl UnwindSafe for ModelColumn
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