Skip to content
How Rust Rewired My Thinking After 6 Years
Fundamentals 19 min read

How Rust Rewired My Thinking After 6 Years

A developer reflects on six years of Rust, explaining how its sum types, pattern matching, static dispatch, type-driven development, macros, ownership model, and arena pattern transformed their approach to software design and performance.

21CTO
21CTO
21CTO

A programmer named Martijn Faassen shares how six years of Rust — over four professionally — fundamentally changed his thinking as a developer. He argues that the greater the difference between a new language and one's habitual language, the larger its cognitive impact, and Rust's distinctiveness made that impact profound.

Sum Types (Enums) and Pattern Matching

Faassen contrasts product types (structs) with sum types (enums). A struct like Human { first_name: String, last_name: String } represents all combinations of its fields (a product). An enum like

Person { Human { first_name: String, last_name: String }, Cat { name: String, cuteness: Cuteness } }

represents a value that is either a Human or a Cat (a sum). Rust's match forces exhaustive handling of every variant, eliminating whole classes of bugs. He notes that languages lacking sum types feel impoverished; simulating them with tag fields is a poor substitute because the language should handle this fundamental concern.

Enums vs. Abstraction (Interfaces/Inheritance)

In OOP, variants are handled via interfaces and dynamic dispatch. While this enables open extension (Open/Closed Principle), it incurs runtime overhead and requires designing an abstraction upfront. For a closed domain (only Human and Cat), an enum is simpler, faster, and statically checked. The compiler ensures no variant is missed when adding a new one. Enums do not prevent adding methods, so they remain flexible.

Static Dispatch and Generics

Rust makes dispatch strategies explicit: dynamic (trait objects), conditional (if/else), enum matching, and static (generics). With struct Group<T> { ... } and let cat_group: Group<Cat> = Group::new();, the compiler knows every element is a Cat, enabling direct calls without per-element branching. This compile-time assembly avoids indirect calls and improves performance in hot paths.

Type-Driven Development

Faassen traces his journey from C++ to Python (dynamic typing) and back to ergonomic static types. Beyond catching errors early and enabling optimization, types shape architecture. He draws analogies: tests force API clarity (TDD), documentation forces understanding (DDD), and types force domain modeling (Type-Driven Development). Enums express parsing rather than validation. This is iterative — types evolve with understanding — not big upfront design.

Macros: Compile-Time Magic

Rust achieves Python-like convenience (pickle, Pydantic) at compile time via macros. #[derive(Serialize, Deserialize)] on a struct generates serialization code for JSON, TOML, etc. clap derives a CLI parser from a struct definition. Macros generate code that the optimizer treats like hand-written code. Faassen warns macros belong in frameworks, not application logic, but acknowledges they enable powerful declarative patterns.

Ownership and Architecture

Rust's ownership prevents mutable aliasing and cycles by default. Code that mutates shared objects or builds parent-child cycles (common in Python/Java) fails to compile. This forces separation of construction from usage, reducing coupling and eliminating "spooky action at a distance." While local code may seem verbose, large-scale data flow becomes clearer.

The Arena Pattern

To work around ownership restrictions for graph-like structures, Rustaceans use arenas: store nodes in a vector and reference them by index. This enables cyclic references without reference counting, improves cache locality (fast traversal), allows bulk allocation, and enables deduplication. Arenas are pervasive in Rust and encourage writing code that maps well to hardware.

Performance as a Qualitative Enabler

Rust surfaces costs (reference counting, dynamic dispatch) in the type system, making trade-offs visible. While premature optimization is a risk, predictable performance unlocks new architectural possibilities. Faassen cites his experimental library Colchis, which holds massive JSON datasets in memory with full random access — something he never considered feasible before Rust.

Conclusion

Rust is the hardest language Faassen has learned, and therefore the most influential. Its simple parts (enums, tooling) ease daily work; its deeper complexities (ownership, lifetimes) appear when needed. Unlearning old habits is the real challenge. Rust expanded his creative envelope, and he is grateful for the journey.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceRustmemory safetyownershippattern matchingmacrosarena patternstatic dispatchsum typestype-driven development
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.