A Rust library for representing and manipulating Kerml models using statically generated, trait-based structures that simulate object-oriented paradigms in a Rust-idiomatic way.
Kerml is a model specification language with an object-oriented architecture, including classes, inheritance, attributes, and method overloading. Rust, however, is not inherently object-oriented, which poses a challenge for faithful Kerml integration.
This crate provides a statically generated Rust implementation of the Kerml specification using advanced trait-based encoding to model:
- Class hierarchies and inheritance
- Attribute access across superclasses
- Method overloading
- Upcasting and downcasting
The library has been generated from an ecore specification of Kerml, using a custom code generator built specifically for this purpose.
The crate is composed of four main modules:
root: Corresponds to the root section of the Kerml specificationcore: Models the core elementskernel: Encodes the kernel-level types and behaviorsgenerated: Automatically generated code from the Kerml Ecore spec
Each class in Kerml maps to a dedicated Rust module containing:
- A struct representing the class and its attributes
- Traits for accessing attributes (including inherited ones)
- Enums for modeling subclass relationships
- Upcast/downcast traits and implementations
- Traits for methods, including overloading support
For each class, we encode inheritance and method overloading as follows:
- Structs represent attributes and store instances of superclasses.
- Enums model subclass polymorphism with variants like
Itselfor subclass enums. - Traits provide:
- Attribute access (local and inherited)
- Upcasting and downcasting
- Default and overloaded method handling via a
DescendantOf<T>pattern
This design enables:
- Statically typed method dispatch with overload support
- Encapsulation of inheritance trees
- Compile-time guarantees on method implementation completeness
The Import class:
- Inherits from
Relationship - Has two subclasses:
MembershipImportandNamespaceImport
Rust representation includes:
- A struct
Importwith:- Fields for its own attributes
- A
relationship_instfield
- A trait for each superclass (
Relationship) to access inherited attributes - An enum
ImportEnumwith:Itself(Import)- Variants for each subclass enum
- Upcast and downcast traits
- Method traits with default and overload-aware resolution
For each class:
- Traits are defined for each method (inherited and local)
- The programmer must implement the methods declared for the current class
- Traits support overloads via a generic
DescendantOf<OriginClass>pattern with an associatedViatype
This crate is a prototype and is not yet production-ready.