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

into_keys and into_values do not work with AHashMap #118

Closed
dsemi opened this issue May 30, 2022 · 2 comments · Fixed by #136
Closed

into_keys and into_values do not work with AHashMap #118

dsemi opened this issue May 30, 2022 · 2 comments · Fixed by #136

Comments

@dsemi
Copy link

dsemi commented May 30, 2022

Rust recently added into_keys and into_values that consume self and return an iterator over the moved keys or values. This doesn't work with AHashMap because the new functions are used by AHashMap via Deref<Target = HashMap<K, V, S>>:

error[E0507]: cannot move out of dereference of `AHashMap<&str, i64>`
   --> src/file.rs:30:5
    |
30  |     tbl.into_values().max()
    |     ^^^^-------------
    |     |   |
    |     |   value moved due to this method call
    |     move occurs because value has type `HashMap<&str, i64, ahash::RandomState>`, which does not implement the `Copy` trait
    |
note: this function takes ownership of the receiver `self`, which moves value
   --> /home/dsemi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/collections/hash/map.rs:454:24
    |
454 |     pub fn into_values(self) -> IntoValues<K, V> {
    |                        ^^^^

@notgull
Copy link

notgull commented May 30, 2022

Huh, I always thought AHashMap was just a typedef.

@BratSinot
Copy link

As workaround, we can use HashMap::into_values directly.

    let map: AHashMap<_, _> = AHashMap::from_iter([("a", 1), ("b", 2)]);
    let arr = HashMap::into_values(map.into()).collect::<Box<[_]>>();
    println!("{:?}", arr);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants