This repository contains the source code and examples for the presentation "How to Fit an Elephant in a Rusty Refrigerator: Conquering a 7,000-Type API" delivered at the October 2025 conference.
├── Domain Model.md # Domain model documentation
├── key data type polymorhism traits.md # Java polymorphism traits analysis
├── preso.md # Presentation outline
├── enum_polymorphism/ # Enum-based polymorphism demo
│ ├── src/
│ │ ├── lib.rs # 4 core polymorphism operations
│ │ └── model.rs # Tree-structured enum hierarchy
│ └── README.md # Detailed project documentation
├── trait_polymorphism/ # Trait-based polymorphism demo
│ ├── src/
│ │ ├── lib.rs # Main library and tests
│ │ ├── traits.rs # Animal trait hierarchy
│ │ ├── structs.rs # Concrete implementations
│ │ └── operations.rs # 4 core polymorphism operations
│ └── README.md # Detailed project documentation
└── Cargo.toml # Workspace configuration
- Animal (root) → Mammal → Carnivore/Herbivore → Lion
- Each level has specific properties and behaviors
- Maintains type safety while enabling polymorphic operations
- Upcasting: Automatic conversion to parent types
- Runtime Type Identification: Pattern matching and type checking
- Downcasting: Safe extraction of specific variants
- Polymorphic Collections: Uniform processing of different types
- Embedded discriminator field (
type
) - Clean, readable format for API integration
- Example:
{"type":"Lion","name":"Simba","habitat":"Grassland","pack_size":5,"mane_length":12.5,"roar_volume":110}
This repository demonstrates two different approaches to polymorphism in Rust:
- Best for: Closed sets of types, flat data structures, array element types
- Advantages: Fast pattern matching, stack allocation, simple serialization
- Use case: The 3,000+ array types mentioned in the presentation
- Best for: Open extension, deep inheritance hierarchies, behavior polymorphism
- Advantages: Dynamic dispatch, cross-trait casting (VimAny pattern), extensible
- Use case: The complex inheritance hierarchies with 7,000+ types
Feature | Enums | Traits |
---|---|---|
Extension | Closed (modify enum) | Open (add new types) |
Memory | Stack allocation | Heap + vtable |
Performance | Direct match, faster | Dynamic dispatch overhead |
Serialization | Simple with serde | Complex (needs typetag) |
Type Safety | Compile-time matching | Runtime downcasting |
# Run enum-based polymorphism demo
cargo test --package enum_polymorphism -- --nocapture
# Run trait-based polymorphism demo
cargo test --package trait_polymorphism -- --nocapture
# Run specific test with output
cargo test --package enum_polymorphism test_all_types_serialization -- --nocapture
# Build all projects
cargo build
Kiril Karaatanasov
With 27 years in software engineering, from R&D leadership to architecting APIs at scale. At VMware (now Broadcom), modernized SOAP-to-JSON for vCenter's API and authored VMware's internal REST standard (2016). Currently obsessed with taming legacy APIs in Rust—slashing compile times by 90%.
This project is for educational and presentation purposes.