pub struct TypeContext { /* private fields */ }Expand description
Context for type resolution and type checking
Maintains a registry of user-defined types and provides field lookup, type compatibility checking, and type inference from literal values.
§Example
ⓘ
use elo_rust::codegen::types::{TypeContext, TypeInfo, RustType};
let mut context = TypeContext::new();
let mut user_type = TypeInfo::new("User");
user_type.add_field("email", RustType::String);
user_type.add_field("age", RustType::Integer);
context.register_type("User", user_type);
// Look up field types
assert_eq!(
context.get_field_type("User", "email"),
Some(&RustType::String)
);Implementations§
Source§impl TypeContext
impl TypeContext
Sourcepub fn register_type(&mut self, name: &str, type_info: TypeInfo)
pub fn register_type(&mut self, name: &str, type_info: TypeInfo)
Register a new custom type in the context
§Arguments
name- The name of the type (e.g., “User”, “Product”)type_info- The type information including field definitions
Sourcepub fn list_all_type_names(&self) -> Vec<String>
pub fn list_all_type_names(&self) -> Vec<String>
Get all registered type names
Sourcepub fn infer_from_literal(&self, literal: &str) -> RustType
pub fn infer_from_literal(&self, literal: &str) -> RustType
Infer the type from a literal value
Attempts to determine the Rust type of a literal string by:
- Trying to parse as integer
- Trying to parse as float
- Checking for boolean keywords (true/false)
- Checking for quoted strings
§Arguments
literal- The literal value as a string
§Returns
The inferred RustType, or RustType::Unknown if unable to infer
Trait Implementations§
Source§impl Clone for TypeContext
impl Clone for TypeContext
Source§fn clone(&self) -> TypeContext
fn clone(&self) -> TypeContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TypeContext
impl Debug for TypeContext
Source§impl Default for TypeContext
impl Default for TypeContext
Source§fn default() -> TypeContext
fn default() -> TypeContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TypeContext
impl RefUnwindSafe for TypeContext
impl Send for TypeContext
impl Sync for TypeContext
impl Unpin for TypeContext
impl UnsafeUnpin for TypeContext
impl UnwindSafe for TypeContext
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
Mutably borrows from an owned value. Read more