Posts

Showing posts from February, 2022

A Deep Dive Into the Rust Type System

Introduction This post is going to be a deep dive into Rust's type system and how compares to the Scala 3 type system. I use the Scala type system as comparison as I know it well and it's one of the most powerful type systems available in a "production grade" language. It can express most everything found in the Rust type system (except everything related to borrowing checking of course), but the opposite is not true since Scala has many advanced type features which Rust lacks (for example union/intersection types, subtyping, HKT's etc. etc.). Type Relationships The relationships between types in Scala are specified using subtyping ( C extends A with B ), union types ( type C = A | B ) and intersection types ( type C = A & B ). In Rust there are  no  relationships between types (except type aliases, type B = A ) . There is however a way to specify subtype-like relationships for traits, which we will get into in the next section. Traits Rust traits is a desc