These are chat archives for rust-lang/rust

16th
Mar 2017
Abiel Parra (Quarry)
@Heeled-Jim
Mar 16 2017 02:03
Hi everyone, I am a rustacean from Mexico City, part of the Rust MX community (https://github.com/rustmx) and the accountable one for the Rust projects within the community of Mozilla MX (https://github.com/mozillamexico) :)
Christian Howe
@cjhowe7
Mar 16 2017 02:44
hi
Ashley Mannix
@KodrAus
Mar 16 2017 07:59
Thankyou to whomever impl'd AsRef<[u8]> for String and str :clap: (I know it's been that way for a long time, but just noticed)
Clément
@claisne
Mar 16 2017 10:31
Hi rust beginner here, I have a Hashmap, and would like to get all the couples from that hashmap , while keeping them mutables.
here is a sample snippet which is not correct, since I cannot borrow mutability twice. Could you point me to a solution ?
for (player, other) in self.players.values_mut().zip(self.players.values_mut()) {
    if player.id != other.id {
        player.update_target(other);
    }
}
Vladimir
@Crazy-Owl
Mar 16 2017 10:48
Have you seen the Entry API?
oh, nevermind, it's not applicable here
Clément
@claisne
Mar 16 2017 10:54
Maybe I should change the data modelisation.
Bit strange that I can't get mutable couples from a HashMap simply.
Vladimir
@Crazy-Owl
Mar 16 2017 10:54
you can generate pairs of keys first
Aleksey Kladov
@matklad
Mar 16 2017 10:55
Yeah, getting two mutable references inside a container is not really possible in Rust, because it is difficult to check at compile time that they reference different elements.
Vladimir
@Crazy-Owl
Mar 16 2017 10:55
should the second element be mutable?
Clément
@claisne
Mar 16 2017 10:55
no, i just want to check a condition and update the first element.
Aleksey Kladov
@matklad
Mar 16 2017 10:56
Even if only one of them is mutable, you won't be able to get two references safely
Vladimir
@Crazy-Owl
Mar 16 2017 10:56
yep
Vladimir
@Crazy-Owl
Mar 16 2017 10:57
but you can, say, get an object of UpdateOptions (or any name you could think of) from other, then pass it to player mutable object
Clément
@claisne
Mar 16 2017 10:59
doesn't it require to still have an immutable borrow from players and mutable at the same time ?
i may end up cloning the all thing i guess
Aleksey Kladov
@matklad
Mar 16 2017 11:00
Yep, making Player immutable and doing something like update(players: &HashMap<String, Player>) -> HashMap<String, Player> should work.
Clément
@claisne
Mar 16 2017 11:03
I am not sure I follow
you mean I would need to clone the data ?
Vladimir
@Crazy-Owl
Mar 16 2017 11:04
you can clone just the data you need to update
Clément
@claisne
Mar 16 2017 11:04
oh ok got it. thanks I'll try that way