Type

Enum Type 

pub enum Type {
Show 29 variants Bool, String, I8, I16, I32, I64, U8, U16, U32, U64, Uuid, Key(ModelId), Model(ModelId), ForeignKey(FieldId), List(Box<Type>), Record(Vec<Type>), Bytes, Decimal, BigDecimal, Timestamp, Zoned, Date, Time, DateTime, Null, SparseRecord(PathFieldSet), Unit, Unknown, Union(TypeUnion),
}
Expand description

Statement-level type system for values and expressions within Toasty’s query engine.

stmt::Type represents types at both the application level (models, fields, Rust types) and the query engine level (tables, columns, internal processing). These types are internal to Toasty - they describe how Toasty views and processes data throughout the entire query pipeline, from user queries to driver execution.

§Distinction from Database Types

Toasty has two distinct type systems:

  1. stmt::Type (this type): Application and query engine types

    • Types of stmt::Value and stmt::Expr throughout query processing
    • Represents Rust primitive types: I8, I16, String, etc.
    • Works at both model level (application) and table/column level (engine)
    • Internal to Toasty’s query processing pipeline
  2. schema::db::Type: Database storage types

    • External representation for the target database
    • Database-specific types: Integer(n), Text, VarChar(n), etc.
    • Used only at the driver boundary when generating database queries

The key distinction: stmt::Type is how Toasty views types internally, while schema::db::Type is how the database stores them externally.

§Query Processing Pipeline

Throughout query processing, all values and expressions are typed using stmt::Type, even as they are transformed and converted:

Application Level (Model/Field)

  • User writes queries referencing models and fields
  • Types like stmt::Type::Model(UserId), stmt::Type::String
  • Values like stmt::Value::String("alice"), stmt::Value::I64(42)

Query Engine Level (Table/Column)

  • During planning, queries are “lowered” from models to tables
  • Values may be converted between types (e.g., Model → Record, Id → String)
  • All conversions are from stmt::Type to stmt::Type
  • Still using the same type system, now at table/column abstraction level

Driver Boundary (Database Storage)

  • Statements with stmt::Value (typed by stmt::Type) passed to drivers
  • Driver consults schema to map stmt::Typeschema::db::Type
  • Same stmt::Type::String may map to different database types based on schema configuration

§Schema Representation

Each column in the database schema stores both type representations:

  • column.ty: stmt::Type - How Toasty views this column internally
  • column.storage_ty: Option<db::Type> - How the database stores it externally

This dual representation enables flexible mapping. For instance, stmt::Type::String might map to db::Type::Text in one column and db::Type::VarChar(100) in another, depending on schema configuration and database capabilities.

§See Also

Variants§

§

Bool

Boolean value

§

String

String type

§

I8

Signed 8-bit integer

§

I16

Signed 16-bit integer

§

I32

Signed 32-bit integer

§

I64

Signed 64-bit integer

§

U8

Unsigned 8-bit integer

§

U16

Unsigned 16-bit integer

§

U32

Unsigned 32-bit integer

§

U64

Unsigned 64-bit integer

§

Uuid

128-bit universally unique identifier (UUID)

§

Key(ModelId)

An instance of a model key

§

Model(ModelId)

An instance of a model

§

ForeignKey(FieldId)

An instance of a foreign key for a specific relation

§

List(Box<Type>)

A list of a single type

§

Record(Vec<Type>)

A fixed-length tuple where each item can have a different type.

§

Bytes

§

Decimal

A fixed-precision decimal number. See [rust_decimal::Decimal].

§

BigDecimal

An arbitrary-precision decimal number. See [bigdecimal::BigDecimal].

§

Timestamp

An instant in time represented as the number of nanoseconds since the Unix epoch. See [jiff::Timestamp].

§

Zoned

A time zone aware instant in time. See [jiff::Zoned]

§

Date

A representation of a civil date in the Gregorian calendar. See [jiff::civil::Date].

§

Time

A representation of civil “wall clock” time. See [jiff::civil::Time].

§

DateTime

A representation of a civil datetime in the Gregorian calendar. See [jiff::civil::DateTime].

§

Null

The null type. Represents the type of a null value and is cast-able to any type. Also used as the element type of an empty list whose item type is not yet known.

§

SparseRecord(PathFieldSet)

§

Unit

Unit type

§

Unknown

A type that could not be inferred (e.g., empty list)

§

Union(TypeUnion)

A union of possible types.

Used when a match expression’s arms can produce values of different types (e.g., a mixed enum where unit arms return I64 and data arms return Record). A value is compatible with a union if it satisfies any of the member types.

Implementations§

§

impl Type

pub fn is_i8(&self) -> bool

pub fn is_i16(&self) -> bool

pub fn is_i32(&self) -> bool

pub fn is_i64(&self) -> bool

pub fn is_u8(&self) -> bool

pub fn is_u16(&self) -> bool

pub fn is_u32(&self) -> bool

pub fn is_u64(&self) -> bool

§

impl Type

pub fn sparse_record(fields: impl Into<PathFieldSet>) -> Type

pub fn empty_sparse_record() -> Type

§

impl Type

pub fn list(ty: impl Into<Type>) -> Type

pub fn unwrap_list_ref(&self) -> &Type

pub fn is_bool(&self) -> bool

pub fn is_model(&self) -> bool

pub fn is_list(&self) -> bool

pub fn is_string(&self) -> bool

pub fn is_unit(&self) -> bool

pub fn is_record(&self) -> bool

pub fn is_bytes(&self) -> bool

pub fn is_decimal(&self) -> bool

pub fn is_big_decimal(&self) -> bool

pub fn is_uuid(&self) -> bool

pub fn is_sparse_record(&self) -> bool

pub fn is_numeric(&self) -> bool

Returns true if this type is a numeric integer type.

Numeric types include all signed and unsigned integer types: I8, I16, I32, I64, U8, U16, U32, U64.

This does not include decimal types or floating-point types.

§Examples
assert!(Type::I32.is_numeric());
assert!(Type::U64.is_numeric());
assert!(!Type::String.is_numeric());
assert!(!Type::Bool.is_numeric());

pub fn cast(&self, value: Value) -> Result<Value, Error>

pub fn is_subtype_of(&self, other: &Type) -> bool

Checks whether self (the actual/inferred type) is assignable to other (the expected type).

This is a subtype check, NOT strict equality:

  • Type::Null matches any type (in either direction), since it represents “we don’t know what type this is”
  • A concrete type is assignable to a Type::Union if it matches any member
  • A Type::Union is assignable to another union if every member of self matches some member of other
  • Container types (Type::List, Type::Record) check element/field types recursively
§Examples
  • String.is_subtype_of(String) -> true
  • String.is_subtype_of(Null) -> true
  • String.is_subtype_of(Bytes) -> false
  • Record([...]).is_subtype_of(Union([I64, Record([...])])) -> true
  • I64.is_subtype_of(Union([I64, Record(...)])) -> true
  • String.is_subtype_of(Union([I64, Record(...)])) -> false
§

impl Type

pub fn cast_jiff(&self, value: &Value) -> Result<Option<Value>, Error>

Trait Implementations§

§

impl Clone for Type

§

fn clone(&self) -> Type

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
§

impl Debug for Type

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for Type

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Type, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl From<&Type> for Type

§

fn from(value: &Type) -> Type

Converts to this type from the input type.
§

impl From<ModelId> for Type

§

fn from(value: ModelId) -> Type

Converts to this type from the input type.
§

impl PartialEq for Type

§

fn eq(&self, other: &Type) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for Type

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Eq for Type

§

impl StructuralPartialEq for Type

Auto Trait Implementations§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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.
§

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

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,