#Implementing FromIterator on struct

24 messages · Page 1 of 1 (latest)

elder hollow
#

Not sure what to do here. Pls help <3

old vapor
elder hollow
#

oh perfect

old vapor
#

The issue here is that you have an iterator of Dex, but are trying to make a map of (Dex, Pair). In other words, which value should be associated with each key?

elder hollow
#

oh

#

im trying to just have a vec of all the keys of the BTreeMap

#

dont need the keys

old vapor
#

Then you want to collect in something other than a BTreeMap.
Currently, you put the result into the group variable, which means type inference figures out you want a BTreeMap, since otherwise it's a type error.
Do you want to shadow group, maybe?

#

let group = group.keys().cloned().collect::<Vec<_>>();

elder hollow
#

that would just override the first group var wouldnt it

old vapor
#

Note: if you don't need the old group anymore, you can save yourself some clones with .into_keys()

elder hollow
#

oh derp

old vapor
elder hollow
#

oh wow

#

didnt see the .into_keys() trait

#

thank you

old vapor
#

(it's just a method, not a trait 😄)

elder hollow
#

ahhhhhhhhh

#

why wouldnt i need to collect it here?

old vapor
elder hollow
#

oh derp okay

old vapor
#

Just to avoid cloning if you're not going to use group anymore anyway