News for hackers. Stuff that matters.
Re:“Python's batteries are leaking” by new4thaccount on Saturday May 18, 2019 @02:49PM (#19949040)
Yea. I'm using Rust at the moment for fun and the amount of things not in the standard library is crazy to me. What? There is no built-in dictionary? What do I use instead and where is it?

Edit: based off of all the replies below, everyone understands the validity of what I'm trying to say, but also have fortunately pointed out my admittedly grevious error of not knowing you can just import hashmap from stdlib. The extra step is pretty minimal and not a problem. I'm hoping this is covered in the Rust book.

Re:“Python's batteries are leaking” by nicoburns on Saturday May 18, 2019 @03:00PM (#19949102)
Re:“Python's batteries are leaking” by StavrosK on Saturday May 18, 2019 @03:55PM (#19949398)
Oof, I wasted a good hour+ trying to convert from one to the other. Maybe there's an easy way to do this, but not many people on IRC knew (or were available at the time).
Re:“Python's batteries are leaking” by edflsafoiewq on Saturday May 18, 2019 @04:28PM (#19949559)

    use std::iter::FromIterator;
    BTreeMap::from_iter(hash_map.into_iter())
Re:“Python's batteries are leaking” by steveklabnik on Saturday May 18, 2019 @05:54PM (#19949946)
Or .into_iter().collect(), I believe. No import needed.
Re:“Python's batteries are leaking” by a1369209993 on Saturday May 18, 2019 @06:12PM (#19950017)
Assuming the keys are Hash + Ord, wouldn't that just be:

  for (k,v) in &src
    { dst.insert(k,v); }

?
Re:“Python's batteries are leaking” by StavrosK on Sunday May 19, 2019 @01:26PM (#19954362)
Yes, that's what I ended up doing, but the error confused me and I ended up looking for a less hacky way for more than an hour until I said "fuck it" and just did that.
Re:“Python's batteries are leaking” by new4thaccount on Saturday May 18, 2019 @03:46PM (#19949355)
At least the first one seems pretty straightforward and thanks for replying. I only just started and have a lot to learn.
Re:“Python's batteries are leaking” by qbaqbaqba on Sunday May 19, 2019 @02:35AM (#19951808)
Are they compatible?
Re:“Python's batteries are leaking” by jonesetc on Saturday May 18, 2019 @03:09PM (#19949159)
I know it's not the whole point, but there is a hash map and sorted (btree) map in the std collections.

That being said the point still stands, I remember specifically feeling it at the lack of included regex. I overall prefer the slim std lib of rust over the massive python though. Especially with the community being pretty good about nominating de facto standard packages like for regex.

Re:“Python's batteries are leaking” by resoluteteeth on Saturday May 18, 2019 @02:55PM (#19949076)
Yeah Rust is pretty extreme. I was just trying to generate a random number in it and was pretty surprised to find out that at some point it did have this functionality in the standard library but they actually removed it and now it's a separate crate.
Re:“Python's batteries are leaking” by nicoburns on Saturday May 18, 2019 @03:02PM (#19949112)
That is actually being considered for inclusion at some point. It was mainly excluded due it not being ready and them not wanting to commit to the existing API. That said, I like the Rust way. Including a library is pretty easy, and it mains you get the best API as the main one (rather than a stdlib function that is "good enough", and another library to use if you really care about that functionality).
Re:“Python's batteries are leaking” by CDSlice on Saturday May 18, 2019 @03:01PM (#19949108)
If you are using dictionary in the Python sense, Rust has that built in too, you just have to import it from the standard library collections module.

https://doc.rust-lang.org/std/collections/struct.HashMap.htm...

Re:“Python's batteries are leaking” by jzoch on Saturday May 18, 2019 @02:56PM (#19949080)
You mean a map? It's in the standard library.
Re:“Python's batteries are leaking” by new4thaccount on Saturday May 18, 2019 @03:50PM (#19949375)
Yep. Map/Hash/Dictionary.

I didn't know it was included in stdlib (I really thought it wasn't) and feel idiotic now. It is still odd (having a primarily scripting background and not coming from the systems side) that I have to include what seems to be essentially an import statement at the top. I guess it is a lot more efficient that way though. Thanks for pointing out my error!

Re:“Python's batteries are leaking” by jgibson on Saturday May 18, 2019 @02:57PM (#19949089)
Er, doesn't hashmap do pretty much the same thing? https://doc.rust-lang.org/std/collections/struct.HashMap.htm...