Skip to content

Chapter 8.3 zip doesn't return tuple #2762

@gimKondo

Description

@gimKondo

of collection types, including `HashMap`. For example, if we had the team names
and initial scores in two separate vectors, we could use the `zip` method to
create a vector of tuples where “Blue” is paired with 10, and so forth. Then we
could use the `collect` method to turn that vector of tuples into a hash map,
as shown in Listing 8-21.

This description say

For example, if we had the team names and initial scores in two separate vectors, we could use the zip method to create a vector of tuples where “Blue” is paired with 10, and so forth. Then we could use the collect method to turn that vector of tuples into a hash map

But actually zip method returns std::iter::Zip<std::slice::Iter<std::string::String>, std::slice::Iter<i32>> .
Also, if we compile vec![(String::from("Blue"), 10), (String::from("Yellow"), 50)].collect() , we get error like this.

method cannot be called on Vec<(String, {integer})> due to unsatisfied trait bounds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions