2 ms·
I like that the iterator trait has a thread-safe design. C#'s is a pain in the neck: having MoveMext and Current as separate methods was a bad idea.
by moomin 13y ago
I like that the iterator trait has a thread-safe design. C#'s is a pain in the neck: having MoveMext and Current as separate methods was a bad idea.
- kibwen 13y agoThat was never a concern; it would take signficantly more work to make iterators non-thread-safe. Welcome to Rust. :) EDIT: And if you're referring to the way that our iterators automatically guarantee that iterator invalidation just can't happen, well, that's simply how borrowed pointers work! No extra effort required (not that borrowed pointers are the easiest thing to grok in the first place, mind you...).
- moomin 13y agoTo clarify, having advance return the result means the design can be used to read from an external queue on multiple threads. C#'s IEnumerable can't do this, because the interface assumes only one consumer. (Edit: I should point out C# is not the only platform that gets this wrong. C++/STL has the same design.)
- ajanuary 13y agoThe problem C# has is that wrapping every iteration result in a container would make iteration ever more expensive than it currently is. The Option type in Rust is incredibly cheap compared to the equivalent struct or class in C#.
- moomin 13y agoOK, I'll happily admit to a lack of deep knowledge here, but returning a struct of <success, value> doesn't strike me as less expensive than doing two function calls to get the same data. I'm more inclined to suspect they didn't do it that way because C#1 didn't have generics. I'll happily admit Rust's more efficient, though.