One Data Type Representing Multiple Kinds of Data

Sometimes, a data value might need to be one of multiple different data types. Rust has three ways of addressing that situation without breaking strict type safety: enumerations, trait objects, and Any. Each approach has strengths and weaknesses, so we'll examine them all and talk about when each is appropriate.

In this chapter, we're going to learn about the following:

  • What an enumeration is
  • How to create an enumeration type
  • How to create enumeration values
  • How to use the information stored in an enumeration value
  • What a trait and a trait object are
  • How to create a trait
  • How to create a trait object
  • How to use a trait object
  • What Any is
  • How to use Any
  • What enumerations are good for, what trait objects are good for, and what Any is good for
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.5.201