pub enum TypeAnnotation {
Show 14 variants
Basic(String),
Array(Box<TypeAnnotation>),
Tuple(Vec<TypeAnnotation>),
Object(Vec<ObjectTypeField>),
Function {
params: Vec<FunctionParam>,
returns: Box<TypeAnnotation>,
},
Union(Vec<TypeAnnotation>),
Intersection(Vec<TypeAnnotation>),
Generic {
name: TypePath,
args: Vec<TypeAnnotation>,
},
Reference(TypePath),
Void,
Never,
Null,
Undefined,
Dyn(Vec<TypePath>),
}Variants§
Basic(String)
Basic types: number, string, bool, row, pattern, etc.
Array(Box<TypeAnnotation>)
Vector type: T[] or Vec
Tuple(Vec<TypeAnnotation>)
Tuple type: [T1, T2, T3]
Object(Vec<ObjectTypeField>)
Object type: { field1: T1, field2?: T2 }
Function
Function type: (T1, T2) => T3
Union(Vec<TypeAnnotation>)
Union type: T1 | T2 | T3 (discriminated union - value is ONE of the types)
Intersection(Vec<TypeAnnotation>)
Intersection type: T1 + T2 (structural merge - value has ALL fields from both types) Only valid for object/interface types. Field collisions are compile-time errors.
Generic
Generic type: Map<K, V>
Reference(TypePath)
Type reference (custom type or type alias)
Void
Void type
Never
Never type
Null
Null type
Undefined
Undefined type
Dyn(Vec<TypePath>)
Trait object type: dyn Trait1 + Trait2 Represents a type-erased value that implements the given traits
Implementations§
Source§impl TypeAnnotation
impl TypeAnnotation
pub fn option(inner: TypeAnnotation) -> Self
pub fn option_inner(&self) -> Option<&TypeAnnotation>
pub fn into_option_inner(self) -> Option<TypeAnnotation>
pub fn is_option(&self) -> bool
Sourcepub fn as_simple_name(&self) -> Option<&str>
pub fn as_simple_name(&self) -> Option<&str>
Extract a simple type name if this is a Reference or Basic type
Returns Some(type_name) for:
TypeAnnotation::Reference(path)- e.g.,Currency,foo::MyTypeTypeAnnotation::Basic(name)- e.g.,number,string
Returns None for complex types like arrays, tuples, functions, etc.
Sourcepub fn as_type_name_str(&self) -> Option<&str>
pub fn as_type_name_str(&self) -> Option<&str>
Extract the type name string for Basic or Reference variants.
Handles the Basic(name) | Reference(path) pattern uniformly.
Sourcepub fn to_type_string(&self) -> String
pub fn to_type_string(&self) -> String
Convert a type annotation to its full string representation.
Trait Implementations§
Source§impl Clone for TypeAnnotation
impl Clone for TypeAnnotation
Source§fn clone(&self) -> TypeAnnotation
fn clone(&self) -> TypeAnnotation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more