Comparing Traits in Rust to Type Classes in Scala
I have been reading The Rust Programming Language and Scala with Cats simultaneously for the last couple of weeks to refresh my memory in both topics. While reading about Traits in “the Rust book” I noticed how similar Rust’s Traits and Scala’s Type Classes are. Let me walk you through the example in the Rust book and translate the code into Scala.
Update: I have added Scala 3 code samples to the very bottom of the article.
It all starts with defining a common “summarize” behavior in a trait that will allow us to get…