FieldTy

Enum FieldTy 

Source
pub enum FieldTy {
    Primitive(FieldPrimitive),
    Embedded(Embedded),
    BelongsTo(BelongsTo),
    HasMany(HasMany),
    HasOne(HasOne),
}
Expand description

The type of a Field, distinguishing primitives, embedded types, and relation variants.

§Examples

use toasty_core::schema::app::{FieldPrimitive, FieldTy};
use toasty_core::stmt::Type;

let ty = FieldTy::Primitive(FieldPrimitive {
    ty: Type::String,
    storage_ty: None,
    serialize: None,
});
assert!(ty.is_primitive());
assert!(!ty.is_relation());

Variants§

§

Primitive(FieldPrimitive)

A primitive (scalar) field backed by a single column.

§

Embedded(Embedded)

An embedded struct or enum, flattened into the parent table.

§

BelongsTo(BelongsTo)

The owning side of a relationship (stores the foreign key).

§

HasMany(HasMany)

The inverse side of a one-to-many relationship.

§

HasOne(HasOne)

The inverse side of a one-to-one relationship.

Implementations§

Source§

impl FieldTy

Source

pub fn is_primitive(&self) -> bool

Returns true if this is a FieldTy::Primitive.

Source

pub fn as_primitive(&self) -> Option<&FieldPrimitive>

Returns the inner FieldPrimitive if this is a primitive field.

Source

pub fn as_primitive_unwrap(&self) -> &FieldPrimitive

Returns the inner FieldPrimitive, panicking if this is not a primitive field.

§Panics

Panics if self is not FieldTy::Primitive.

Source

pub fn as_primitive_mut_unwrap(&mut self) -> &mut FieldPrimitive

Returns a mutable reference to the inner FieldPrimitive, panicking if this is not a primitive field.

§Panics

Panics if self is not FieldTy::Primitive.

Source

pub fn is_embedded(&self) -> bool

Returns true if this is a FieldTy::Embedded.

Source

pub fn as_embedded(&self) -> Option<&Embedded>

Returns the inner Embedded if this is an embedded field.

Source

pub fn as_embedded_unwrap(&self) -> &Embedded

Returns the inner Embedded, panicking if this is not an embedded field.

§Panics

Panics if self is not FieldTy::Embedded.

Source

pub fn as_embedded_mut_unwrap(&mut self) -> &mut Embedded

Returns a mutable reference to the inner Embedded, panicking if this is not an embedded field.

§Panics

Panics if self is not FieldTy::Embedded.

Source

pub fn is_relation(&self) -> bool

Returns true if this is a relation type (BelongsTo, HasMany, or HasOne).

Source

pub fn is_has_n(&self) -> bool

Returns true if this is a HasMany or HasOne relation.

Source

pub fn is_has_many(&self) -> bool

Returns true if this is a FieldTy::HasMany.

Source

pub fn as_has_many(&self) -> Option<&HasMany>

Returns the inner HasMany if this is a has-many field.

Source

pub fn as_has_many_unwrap(&self) -> &HasMany

Returns the inner HasMany, panicking if this is not a has-many field.

§Panics

Panics if self is not FieldTy::HasMany.

Source

pub fn as_has_many_mut_unwrap(&mut self) -> &mut HasMany

Returns a mutable reference to the inner HasMany, panicking if this is not a has-many field.

§Panics

Panics if self is not FieldTy::HasMany.

Source

pub fn as_has_one(&self) -> Option<&HasOne>

Returns the inner HasOne if this is a has-one field.

Source

pub fn is_has_one(&self) -> bool

Returns true if this is a FieldTy::HasOne.

Source

pub fn as_has_one_unwrap(&self) -> &HasOne

Returns the inner HasOne, panicking if this is not a has-one field.

§Panics

Panics if self is not FieldTy::HasOne.

Source

pub fn as_has_one_mut_unwrap(&mut self) -> &mut HasOne

Returns a mutable reference to the inner HasOne, panicking if this is not a has-one field.

§Panics

Panics if self is not FieldTy::HasOne.

Source

pub fn is_belongs_to(&self) -> bool

Returns true if this is a FieldTy::BelongsTo.

Source

pub fn as_belongs_to(&self) -> Option<&BelongsTo>

Returns the inner BelongsTo if this is a belongs-to field.

Source

pub fn as_belongs_to_unwrap(&self) -> &BelongsTo

Returns the inner BelongsTo, panicking if this is not a belongs-to field.

§Panics

Panics if self is not FieldTy::BelongsTo.

Source

pub fn as_belongs_to_mut_unwrap(&mut self) -> &mut BelongsTo

Returns a mutable reference to the inner BelongsTo, panicking if this is not a belongs-to field.

§Panics

Panics if self is not FieldTy::BelongsTo.

Trait Implementations§

Source§

impl Clone for FieldTy

Source§

fn clone(&self) -> FieldTy

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 FieldTy

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<BelongsTo> for FieldTy

Source§

fn from(value: BelongsTo) -> Self

Converts to this type from the input type.
Source§

impl From<HasOne> for FieldTy

Source§

fn from(value: HasOne) -> Self

Converts to this type from the input type.

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