Enum Type
pub enum Type {
}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:
-
stmt::Type(this type): Application and query engine types- Types of
stmt::Valueandstmt::Exprthroughout 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
- Types of
-
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::Typetostmt::Type - Still using the same type system, now at table/column abstraction level
Driver Boundary (Database Storage)
- Statements with
stmt::Value(typed bystmt::Type) passed to drivers - Driver consults schema to map
stmt::Type→schema::db::Type - Same
stmt::Type::Stringmay 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 internallycolumn.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
schema::db::TypeExternal database storage typesstmt::Value- Values typed by this systemstmt::Expr- Expressions typed by this system
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
impl Type
pub fn sparse_record(fields: impl Into<PathFieldSet>) -> Type
pub fn empty_sparse_record() -> Type
§impl 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
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
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::Nullmatches any type (in either direction), since it represents “we don’t know what type this is”- A concrete type is assignable to a
Type::Unionif it matches any member - A
Type::Unionis assignable to another union if every member ofselfmatches some member ofother - Container types (
Type::List,Type::Record) check element/field types recursively
§Examples
String.is_subtype_of(String)-> trueString.is_subtype_of(Null)-> trueString.is_subtype_of(Bytes)-> falseRecord([...]).is_subtype_of(Union([I64, Record([...])]))-> trueI64.is_subtype_of(Union([I64, Record(...)]))-> trueString.is_subtype_of(Union([I64, Record(...)]))-> false
Trait Implementations§
§impl<'de> Deserialize<'de> for Type
impl<'de> Deserialize<'de> for Type
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Type, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Type, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Serialize for Type
impl Serialize for Type
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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> 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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.