pub enum Type {
}Expand description
Represents a type in the mq type system
Variants§
Int
Integer type
Float
Floating point type
Number
Number type (unified numeric type)
String
String type
Bool
Boolean type
Symbol
Symbol type
None
None/null type
Markdown
Markdown document type
Array(Box<Type>)
Array type with element type
Tuple(Vec<Type>)
Tuple type with known element types (e.g., (number, string))
Used when --tuple mode is enabled to track per-element types
for small heterogeneous arrays like [1, "hello"].
Dict(Box<Type>, Box<Type>)
Dictionary type with key and value types
Function(Vec<Type>, Box<Type>)
Function type: arguments -> return type
Union(Vec<Type>)
Union type: represents a value that could be one of multiple types Used for try/catch expressions with different branch types
Record(BTreeMap<String, Type>, Box<Type>)
Record type with known fields and optional row extension (row polymorphism).
The first element is a map of field names to their types.
The second element is the row tail: either RowEmpty (closed record)
or Var(id) (open record that may have additional fields).
Examples:
{a: number, b: string}→Record({"a": Number, "b": String}, RowEmpty){a: number | r}→Record({"a": Number}, Var(r))
RowEmpty
Empty row — marks a closed record with no additional fields
Var(TypeVarId)
Type variable for inference
Never
Never type (bottom type) — represents unreachable code paths.
Produced when type narrowing eliminates all possible types from a union.
For example, Union(Array(String), Array(Number)) minus is_array predicate
leaves no viable types, producing Never for the else-branch.
Implementations§
Source§impl Type
impl Type
Sourcepub fn record(fields: BTreeMap<String, Type>, rest: Type) -> Self
pub fn record(fields: BTreeMap<String, Type>, rest: Type) -> Self
Creates a new record type with known fields
Sourcepub fn union(types: Vec<Type>) -> Self
pub fn union(types: Vec<Type>) -> Self
Creates a new union type from two or more types Automatically normalizes the union (removes duplicates, flattens nested unions)
Sourcepub fn subtract(&self, exclude: &Type) -> Type
pub fn subtract(&self, exclude: &Type) -> Type
Removes a type from a union by discriminant, returning the remaining type.
If this is not a union, returns self unchanged.
If only one type remains after subtraction, returns it directly (unwrapped).
If all members are removed (e.g., Union(Array(String), Array(Number)) minus
Array), returns Type::Never to signal an unreachable code path.
Sourcepub fn is_nullable(&self) -> bool
pub fn is_nullable(&self) -> bool
Checks if this type is nullable (is None or a Union containing None).
Sourcepub fn is_concrete(&self) -> bool
pub fn is_concrete(&self) -> bool
Checks if this type contains no free type variables (is fully concrete)
Sourcepub fn apply_subst(&self, subst: &Substitution) -> Type
pub fn apply_subst(&self, subst: &Substitution) -> Type
Substitutes type variables according to the given substitution
Sourcepub fn can_match(&self, other: &Type) -> bool
pub fn can_match(&self, other: &Type) -> bool
Checks if this type can match with another type (for overload resolution).
This is a weaker check than unification - it returns true if the types could potentially be unified, but doesn’t require them to be identical. Type variables always match.
Sourcepub fn can_branch_unify_with(&self, other: &Type) -> bool
pub fn can_branch_unify_with(&self, other: &Type) -> bool
Strict branch compatibility check for if-expression unification decisions.
Unlike can_match, this treats an unresolved type variable (Var) as incompatible
with any known concrete type. This is used when deciding whether if-expression
branches should be unified or placed in a Union type: if one branch has None in
a tuple element position and another has Var (which might resolve to Number),
we conservatively choose Union to avoid a spurious unification error later.
Var(a)vsVar(b)→true(both unknown; let unification decide)Var(a)vsconcrete→false(Var might not match the concrete type)concretevsVar(a)→false(symmetric)- All other cases mirror
can_match
Sourcepub fn match_score(&self, other: &Type) -> Option<u32>
pub fn match_score(&self, other: &Type) -> Option<u32>
Computes a match score for overload resolution. Higher scores indicate better matches. Returns None if types cannot match.
Scoring:
- Exact match: 100
- Union type: best match among variants (slightly penalized)
- Type variable: 10
- Structural match (array/dict/function): sum of component scores
Source§impl Type
impl Type
Sourcepub fn display_resolved(&self) -> String
pub fn display_resolved(&self) -> String
Formats the type as a string, resolving type variables to their readable names. This is used for better error messages.
Sourcepub fn display_renumbered(&self) -> String
pub fn display_renumbered(&self) -> String
Formats the type with renumbered type variables starting from 'a.
This produces clean, sequential type variable names regardless of internal
slotmap indices, which can be very large due to builtin registrations.
For example, instead of 'y32 or 'x3, this produces 'a, 'b, etc.
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more