Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better explanation #3696

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!

postmeback marked this conversation as resolved.
Show resolved Hide resolved
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,
postmeback marked this conversation as resolved.
Show resolved Hide resolved
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