Skip to main content

ModelColumn

Struct ModelColumn 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: &'static str

Column name as it appears in SQL.

§sql_decl: &'static str

Verbatim 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: RustType

Rust type kind. The compatibility check goes through RustType::is_compatible_with.

§nullable: bool

Whether 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: bool

Whether 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: SchemaFlags

Admin / 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

Source

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();
Source

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.

Source

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.

Source

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).

Source

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_nameFull name).

Source

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

Source§

fn clone(&self) -> ModelColumn

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelColumn

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more