On Fri, Jun 7, 2013 at 12:10 PM, Matthieu Monrocq <matthieu.monr...@gmail.com> >> >> The extent to which you can have mutable iterators in Rust is pretty >> small, because of the memory safety requirement. Iterators can't open >> up a hole allowing multiple mutable references to the same object to >> be obtained, so I don't think mutable bidirectional or random access >> iterators are possible. >> >> Forward iterators can't ever give you an alias because they're a >> single pass over the container. It's an easy guarantee to provide. > > > Is it ? > > In this case it would mean that you can only have one Forward Iterator in > scope (for a given container) at once too (ie, the forward iterator borrows > the container); otherwise you could have two distinct iterators pointing to > the same underlying element.
Yeah, the compiler will only allow you to obtain one mutable iterator at a time. You can obtain any number of immutable ones. > I certainly appreciate the ongoing debate anyway, it's great to see things > being exposed to light and openly discussed. I would like to contribute with > one point: partitioning. > > Sometimes, you would like to partition a container, or point to one of its > elements. > > For example, in C++, you have an overload of insert which takes an iterator > allowing you to point to the routine where the element you ask to insert is > likely to go and thus shaving off a couple comparisons (if you are right). > This requires pointing to a single element, to be contrasted with a range. > > Another example would be partitioning, a partition of a slice can be > represented with two points: the two end-points of the slice and the point > of partition. > > Both of those examples can be represented by ranges (or in C++ iterator) > though they do not themselves imply any iteration. My point, thus, is that > there might be a need for "fingers inside a container" that go beyond basic > iteration. > > -- Matthieu To some extent we have a special case for this with string/vector slices but it's not yet extended to containers in general. The vector module could return two *disjoint* `&mut [T]` slices because the caller is unable to extend them. _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev