Skip to main content

Type

Enum Type 

pub enum Type {
Show 32 variants Bool, String, I8, I16, I32, I64, U8, U16, U32, U64, F32, F64, Uuid, Key(ModelId), Model(ModelId), ForeignKey(FieldId), List(Box<Type>), Record(Vec<Type>), Object, 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

§

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.

§

Object

A document value with named fields — the type-level mirror of Value::Object.

This is how a #[document] column is typed at the database and driver level: purely structural, like a jsonb column. It does not name the embedded model whose fields it stores — that identity is an app/engine concept, and the engine views the same column as Type::Model. The two views are converted at the driver boundary (see the engine’s document lowering and raising).

§

Bytes

A byte array, more efficient than List(U8).

§

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)

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§

§

impl Type

pub fn is_f32(&self) -> bool

Returns true if this type matches the corresponding float variant.

pub fn is_f64(&self) -> bool

Returns true if this type matches the corresponding float variant.

§

impl Type

pub fn is_i8(&self) -> bool

Returns true if this type matches the corresponding integer variant.

pub fn is_i16(&self) -> bool

Returns true if this type matches the corresponding integer variant.

pub fn is_i32(&self) -> bool

Returns true if this type matches the corresponding integer variant.

pub fn is_i64(&self) -> bool

Returns true if this type matches the corresponding integer variant.

pub fn is_u8(&self) -> bool

Returns true if this type matches the corresponding integer variant.

pub fn is_u16(&self) -> bool

Returns true if this type matches the corresponding integer variant.

pub fn is_u32(&self) -> bool

Returns true if this type matches the corresponding integer variant.

pub fn is_u64(&self) -> bool

Returns true if this type matches the corresponding integer variant.

§

impl Type

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

Creates a Type::SparseRecord type with the given field set.

pub fn empty_sparse_record() -> Type

Creates a Type::SparseRecord type with no fields.

§

impl 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());

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.

pub fn is_bool(&self) -> bool

Returns true if this is Type::Bool.

pub fn is_model(&self) -> bool

Returns true if this is Type::Model.

pub fn is_list(&self) -> bool

Returns true if this is Type::List.

pub fn is_string(&self) -> bool

Returns true if this is Type::String.

pub fn is_unit(&self) -> bool

Returns true if this is Type::Unit.

pub fn is_record(&self) -> bool

Returns true if this is Type::Record.

pub fn is_object(&self) -> bool

Returns true if this is Type::Object.

pub fn is_bytes(&self) -> bool

Returns true if this is Type::Bytes.

pub fn is_decimal(&self) -> bool

Returns true if this is Type::Decimal (requires rust_decimal feature).

pub fn is_big_decimal(&self) -> bool

Returns true if this is Type::BigDecimal (requires bigdecimal feature).

pub fn is_uuid(&self) -> bool

Returns true if this is Type::Uuid.

pub fn is_sparse_record(&self) -> bool

Returns true if this is Type::SparseRecord.

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 contains_model(&self) -> bool

Whether this type has a document position (Type::Model).

Values at a document position convert between the engine’s positional records and the named objects drivers consume; such conversions are schema-directed and cannot run in a schema-free context.

pub fn cast(&self, resolve: &impl Resolve, 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, integer width conversions, and — directed by resolve — raising a #[document] position’s named wire object into the embedded model’s positional record.

§Errors

Returns an error if the conversion is not supported, if the value is out of range for the target type, or if a schema-directed conversion cannot resolve its model through resolve.

pub fn cast_from( &self, resolve: &impl Resolve, from: Option<&Type>, value: Value, ) -> Result<Value, Error>

Casts value to this type, additionally directed by the source type when one is known (see super::ExprCast::from).

A model-level from type triggers the document lowering conversion: the engine’s positional record becomes the named object drivers consume. Every other conversion is directed by the target type alone, exactly as Self::cast.

§

impl Type

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

Casts a Value to this jiff temporal type, returning the converted value.

Supports conversions between:

  • String and any jiff type (parsing ISO 8601 format)
  • Any jiff type and String (formatting with fixed 9-digit nanosecond precision)
  • Timestamp and Zoned (via UTC timezone)
  • Timestamp/Zoned and DateTime (via UTC timezone)

Returns Ok(None) if the conversion is not supported for this value/type combination. Returns Err if parsing fails.

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 From<TypeUnion> for Type

§

fn from(value: TypeUnion) -> 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 UnsafeUnpin 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> 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<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

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