pub enum TypeExpr {
Named {
name: String,
args: Vec<TypeExpr>,
span: ExprSpan,
},
Array {
element: Box<TypeExpr>,
span: ExprSpan,
},
Tuple {
elements: Vec<TypeExpr>,
span: ExprSpan,
},
}Expand description
type_expression = identifier [ "(" [ type_expression { "," type_expression } ] ")" ] | "[" type_expression "]" | "(" [ type_expression ["," [ type_expression { "," type_expression } ]] ] ")".
() is the empty tuple type (0 elements); (T) is grouping (same as bare T); (T,) is a
1-element tuple; (T, U, ...) is n-element, no trailing comma. [T] names a rank-one array
whose elements have type T; nested brackets compose recursively. Name(A, B) names a
parameterized (generic) type applying zero or more type arguments (RangeInclusive(f64),
RangeFull()); an identifier immediately followed by ( has no other meaning in type
position, so this is unambiguous with adjacent tuple-grouping syntax.
Fn((A, B), R) reserves structural callable syntax: the first argument must be a tuple
of parameter types and the second is the result. Fn((), R) has no parameters;
Fn((A,), R) has one. This syntax is resolved before host generic-leaf lookup.
Variants§
Named
A single type name, optionally applying type arguments, resolved later through a
TypeResolver.
Fields
Array
A recursively nested array type expression ([T]).
Fields
Tuple
A recursively nested tuple type expression.
Implementations§
Source§impl TypeExpr
impl TypeExpr
Sourcepub fn resolve(&self, resolver: &dyn TypeResolver) -> Result<ResolvedType>
pub fn resolve(&self, resolver: &dyn TypeResolver) -> Result<ResolvedType>
Resolves every named leaf through resolver, preserving the recursive type shape.
§Errors
Returns Err if some named leaf is not recognized by resolver, or Fn lacks
exactly two arguments with a tuple of parameter types first.
- Complexity: O(n) in the number of nodes in this type tree.