-
Book Overview & Buying
-
Table Of Contents
Rust for C++ Developers
By :
We've learned that Rust is a multi-paradigm language. While providing the ability to implement object-oriented designs, it is also strongly influenced by functional programming languages. In this section, we'll first look into modeling problems using Rust enums, and then we'll dive into ways that we can mix the functional and object-oriented styles to take advantage of Rust's multi-paradigm capabilities.
A very similar way to achieve a type of polymorphic behavior is to use Rust enums. Because enums in Rust can contain different states for each variant, they create a natural representation for certain types of problems. Often, in functional languages, we see this technique praised as an excellent way to represent abstract syntax trees (ASTs) in compilers and other tree-based data structures.
While Rust enums specify different states for each variant, it is pattern matching that helps...