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
F32
32-bit floating point number
F64
64-bit floating point number
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
A byte array, more efficient than List(U8).
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)
A record type where only a subset of fields are populated, identified
by a 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§
Source§impl Type
impl Type
Sourcepub fn is_i8(&self) -> bool
pub fn is_i8(&self) -> bool
Returns true if this type matches the corresponding integer variant.
Sourcepub fn is_i16(&self) -> bool
pub fn is_i16(&self) -> bool
Returns true if this type matches the corresponding integer variant.
Sourcepub fn is_i32(&self) -> bool
pub fn is_i32(&self) -> bool
Returns true if this type matches the corresponding integer variant.
Sourcepub fn is_i64(&self) -> bool
pub fn is_i64(&self) -> bool
Returns true if this type matches the corresponding integer variant.
Sourcepub fn is_u8(&self) -> bool
pub fn is_u8(&self) -> bool
Returns true if this type matches the corresponding integer variant.
Sourcepub fn is_u16(&self) -> bool
pub fn is_u16(&self) -> bool
Returns true if this type matches the corresponding integer variant.
Source§impl Type
impl Type
Sourcepub fn sparse_record(fields: impl Into<PathFieldSet>) -> Type
pub fn sparse_record(fields: impl Into<PathFieldSet>) -> Type
Creates a Type::SparseRecord type with the given field set.
Sourcepub fn empty_sparse_record() -> Type
pub fn empty_sparse_record() -> Type
Creates a Type::SparseRecord type with no fields.
Source§impl Type
impl Type
Sourcepub fn list(ty: impl Into<Type>) -> Type
pub fn list(ty: impl Into<Type>) -> Type
Creates a Type::List wrapping the given element type.
§Examples
let ty = Type::list(Type::String);
assert!(ty.is_list());Sourcepub fn as_list_unwrap(&self) -> &Type
pub fn as_list_unwrap(&self) -> &Type
Returns the element type of this list type, panicking if this is not
a Type::List.
§Panics
Panics if the type is not a List variant.
Sourcepub fn is_bool(&self) -> bool
pub fn is_bool(&self) -> bool
Returns true if this is Type::Bool.
Sourcepub fn is_model(&self) -> bool
pub fn is_model(&self) -> bool
Returns true if this is Type::Model.
Sourcepub fn is_list(&self) -> bool
pub fn is_list(&self) -> bool
Returns true if this is Type::List.
Sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Returns true if this is Type::String.
Sourcepub fn is_unit(&self) -> bool
pub fn is_unit(&self) -> bool
Returns true if this is Type::Unit.
Sourcepub fn is_record(&self) -> bool
pub fn is_record(&self) -> bool
Returns true if this is Type::Record.
Sourcepub fn is_bytes(&self) -> bool
pub fn is_bytes(&self) -> bool
Returns true if this is Type::Bytes.
Sourcepub fn is_decimal(&self) -> bool
pub fn is_decimal(&self) -> bool
Returns true if this is [Type::Decimal] (requires rust_decimal feature).
Sourcepub fn is_big_decimal(&self) -> bool
pub fn is_big_decimal(&self) -> bool
Returns true if this is [Type::BigDecimal] (requires bigdecimal feature).
Sourcepub fn is_uuid(&self) -> bool
pub fn is_uuid(&self) -> bool
Returns true if this is Type::Uuid.
Sourcepub fn is_sparse_record(&self) -> bool
pub fn is_sparse_record(&self) -> bool
Returns true if this is Type::SparseRecord.
Sourcepub 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());Sourcepub fn cast(&self, value: Value) -> Result<Value, Error>
pub fn cast(&self, value: Value) -> Result<Value, Error>
Casts value to this type, returning the converted value.
Null values pass through unchanged. Supported conversions include identity casts, string/UUID interchange, string/decimal interchange, record-to-sparse-record, and integer width conversions.
§Errors
Returns an error if the conversion is not supported or if the value is out of range for the target type.
Sourcepub 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 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 UnsafeUnpin 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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.