You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For Copy-able key-values (less general than ToOwned), you could change your example to:
letmut hm = std::collections::HashMap::<String,String>::with_capacity(env.len());
hm.extend(env.iter());// using `Extend<(&K, &V)>`
(edit: I wrote Clone-able at first, but that Extend requires Copy. So this doesn't apply to your String key-values.)
I would expect Into to pass ownership though, in which case you can simply write HashMap::from_iter(env). When using the conversion in an inferrable context, you can write foo(env.into_iter().collect()). Either way, this involves a bit of complexity in rehashing everything, so I don't think it should be hidden behind Into.
However, if raw_entry_mut ever stabilizes, we could possibly do better for conversions that keep the same underlying hasher, because IndexMap also caches the hash values in its internal Bucket. Something like:
Many third party
crate
s require the OG.Sure I can do this:
But it's not as ergonomic as an
Into
orFrom
.The text was updated successfully, but these errors were encountered: