Skip to content

noclue/eurorust25

Repository files navigation

How to Fit an Elephant in a Rusty Refrigerator

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.

Project Structure

├── 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

Key Concepts Demonstrated

1. Tree-Structured Enum Hierarchy

  • Animal (root) → MammalCarnivore/HerbivoreLion
  • Each level has specific properties and behaviors
  • Maintains type safety while enabling polymorphic operations

2. Four Core Polymorphism Operations

  1. Upcasting: Automatic conversion to parent types
  2. Runtime Type Identification: Pattern matching and type checking
  3. Downcasting: Safe extraction of specific variants
  4. Polymorphic Collections: Uniform processing of different types

3. Flat JSON Serialization

  • 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}

Comparison: Enums vs Traits

This repository demonstrates two different approaches to polymorphism in Rust:

Enum-Based Polymorphism (enum_polymorphism)

  • 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

Trait-Based Polymorphism (trait_polymorphism)

  • 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

Running the Code

# 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

Speaker

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%.

License

This project is for educational and presentation purposes.

Related Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages