News for hackers. Stuff that matters.
Re:Rust Sucks If I Fail to Write X by Animats on Friday February 17, 2017 @04:52PM (#13672017)
t seems to be pretty "idiomatic" unsafe Rust, with unsafe used exactly where needed. I haven't really looked at the btreemap in a while.

The number of excuses associated with unsafe code in Rust is excessive.

Re:Rust Sucks If I Fail to Write X by Manishearth on Friday February 17, 2017 @05:35PM (#13672325)
It's not an excuse, I just don't think that your statement that the hashmap code uses unsafe superfluously is correct.
Re:Rust Sucks If I Fail to Write X by comex on Friday February 17, 2017 @07:03PM (#13672804)
It's a bit more complicated than marking the hash value as NonZero because there are currently two parallel arrays: one for hash values, one for (key, value) pairs. So there's nothing in the second array to indicate that an element is missing. (It used to be three arrays, with the keys and values separate, but that "optimization" was actually a terrible layout for the cache. I'd like to see a further improvement where key types that can be hashed trivially, e.g. integers, ditch the hash array altogether.)

I'm fine with the use of `unsafe` here. A hash table can be implemented using safe Rust, but you can squeeze a few percent more performance out of it by using a small amount of unsafe code, in a way that would be very difficult to make safe, without a super fancy dependent type system like ATS plus a ton of annotation overhead. The unsafe code can be vetted relatively thoroughly and is safe from the outside. That kind of practical compromise seems very much in the spirit of Rust...