Lang exposes a Rust-like object model through struct, trait, impl, and struct literals. These constructs transpile to Python classes plus runtime metadata and validation helpers.
- Structs use
struct Name { field: Type }. - Traits use
trait Name { fn method(self) -> Type }. - Inherent methods use
impl Name { ... }. - Trait implementations use
impl Trait for Name { ... }. - Struct literals use
Type { field: value }. - Generic parameters use
Name<T>. - Attached macros use
#name(...)on the next item. See Macros.
struct User<T> {
name: str,
age: int,
}
user = User { name: "Ada", age: 36 }
impl<T> User<T> {
fn rename(self, name: str) {
self.name = name
}
}
trait Named<T> {
fn label(self) -> str
}
impl<T> Named<T> for User<T> {
fn label(self) -> str {
self.name
}
}
user.rename("Vey")
print(user.label())
- Generic parameters are preserved as metadata in v1. They are parsed and recorded, but they are not fully enforced as runtime generic bindings.
- Concrete field annotations such as
strandintare checked at runtime when a struct value is constructed. - Concrete method argument annotations are checked at runtime when the method is called.
- Trait implementations are checked at runtime. An incomplete
impl Trait for Typefails when the generated Python module is loaded. - Derived behavior such as
#derive(debug)expands into normaltraitandimplitems before AST parsing.