Convert A Vec Of Tuples Into A Vec Of Another Type In Rust
Preface
This function takes in a vec of tuples that contain string slices that look like this :
rust
and converts it into a vec of string slices (pulled from the second tuple item) that looks like this :
rust
Code
Here's the code :
rust
Testing
Here's the verification :
rust
I've added the [TODO: Code shorthand span ] turbofish to [TODO: Code shorthand span ] in the [TODO: Code shorthand span ] funciton. Sometimes it's necessary, sometimes it's not. In this case, the code would work without it like this :
rust
// original
vec_of_tuples.iter .map .
// updated
vec_of_tuples.iter .map .collect
I also added the type definitions to ``source`` and ``expected``
in the tests that might not be necessary. That code would look
like:
rust
// original
let source: =
vec!;
let expected: =
vec!;
// updated
let source =
vec!;
let expected =
vec!;
I'm not sure at what points those would be required and what points it's not so I defaulted to including them in the example.