Skip to main content

Field

Struct Field 

Source
pub struct Field {
Show 14 fields pub name: Name, pub dtype: &'static str, pub id: bool, pub keyed: bool, pub many: bool, pub optional: bool, pub unique: bool, pub index: bool, pub pick: Option<Pick>, pub default: Option<Arc<dyn Fn(&mut dyn Writer) + Sync + Send>>, pub link: Option<Link>, pub widget: fn() -> Widget, pub parse: fn(&str, &mut dyn Writer) -> Result<(), StoreError>, pub text: fn(&mut dyn Reader) -> String,
}
Expand description

Spec for one column of a schema.

Fields§

§name: Name

Column name.

§dtype: &'static str

SQL type name (INTEGER, REAL, or TEXT).

§id: bool

Autoincrement primary key column.

§keyed: bool

Primary key with a caller-supplied value.

§many: bool

Virtual many-to-many column, not stored inline.

§optional: bool

Nullable column.

§unique: bool

Unique constraint.

§index: bool

Indexed column.

§pick: Option<Pick>

Fixed choice list, if any.

§default: Option<Arc<dyn Fn(&mut dyn Writer) + Sync + Send>>

Default value factory, if any.

§link: Option<Link>

Reference to another table, if any.

§widget: fn() -> Widget

Widget for this field.

§parse: fn(&str, &mut dyn Writer) -> Result<(), StoreError>

Parses raw text into the field’s value.

§text: fn(&mut dyn Reader) -> String

Renders the field’s value as text.

Implementations§

Source§

impl Field

Source

pub fn cell<T>(name: &'static str) -> Field
where T: Storable + Show,

A plain column storing any Storable + Show type.

Source

pub fn id() -> Field

An autoincrement id primary key column.

Source

pub fn key<T>(name: &'static str) -> Field
where T: Storable + Show,

A caller-supplied primary key column.

Source

pub fn str(name: &'static str) -> Field

A string column.

Source

pub fn check(name: &'static str) -> Field

A boolean column.

Source

pub fn many(name: &'static str) -> Field

A virtual many-to-many column.

Source

pub fn optional(self) -> Field

Marks the column nullable.

Source

pub fn unique(self) -> Field

Adds a unique constraint.

Source

pub fn indexed(self) -> Field

Marks the column indexed.

Source

pub fn default_value(self, value: impl Storable) -> Field

Sets a static default Storable value.

Source

pub fn default( self, make: impl Fn(&mut dyn Writer) + Send + Sync + 'static, ) -> Field

Sets a default value factory.

Source

pub fn references(self, target: &'static str) -> Field

Links to another table’s column ("table.column" or just "table").

Sets a Link to another table.

Source

pub fn reference(&self) -> Option<(Table, Name)>

The referenced (table, column) for a direct link, if any.

Source

pub fn load(&self) -> Widget

The field’s Widget.

Source

pub fn initial(&self) -> Value

The field’s default as a Value, or Value::Null.

Trait Implementations§

Source§

impl Clone for Field

Source§

fn clone(&self) -> Field

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Field

§

impl !UnwindSafe for Field

§

impl Forget for Field

§

impl Freeze for Field

§

impl Send for Field

§

impl Sync for Field

§

impl Unpin for Field

§

impl UnsafeUnpin for Field

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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