Skip to content

Commit

Permalink
Better explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
postmeback authored Jul 8, 2023
1 parent 668c647 commit aeecb29
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/ch08-01-vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ different types. Fortunately, the variants of an enum are defined under the
same enum type, so when we need one type to represent elements of different
types, we can define and use an enum!

For example, say we want to get values from a row in a spreadsheet in which
some of the columns in the row contain integers, some floating-point numbers,
and some strings. We can define an enum whose variants will hold the different
value types, and all the enum variants will be considered the same type: that
of the enum. Then we can create a vector to hold that enum and so, ultimately,
holds different types. We’ve demonstrated this in Listing 8-9.
In order to retrieve values from a spreadsheet row where the columns may contain integers,
floating-point numbers, and strings, we can use an enum.
The enum will have variants to represent the different value types,
treating all the variants as the same type (the enum itself).
By creating a vector to store this enum,
we can effectively store values of different types within the same vector.
We’ve demonstrated this in Listing 8-9.

```rust
{{#rustdoc_include ../listings/ch08-common-collections/listing-08-09/src/main.rs:here}}
Expand Down

0 comments on commit aeecb29

Please sign in to comment.