# \[Pre-RFC\] Remove RandomAccessIterator

**URL:** <https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548>\
**Category:** Uncategorized\
**Created:** [February 5, 2015, 8:40pm UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548 "2015-02-05T20:40:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluss](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bluss/32/2264_2.png) [@bluss](https://internals.rust-lang.org/u/bluss)\
**Post date:** [February 5, 2015, 8:40pm UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548/1 "2015-02-05T20:40:00Z")

</div>

I think we should remove [RandomAccessIterator](http://doc.rust-lang.org/std/iter/trait.RandomAccessIterator.html) (“RAI”) from the library.

```
pub trait RandomAccessIterator: Iterator {
    fn indexable(&self) -> usize;
    fn idx(&mut self, index: usize) -> Option<Item>;
}

```

- This trait has been part of libstd for a long time, but it has never found a real use case.

- We have not found a sound and practical expansion into mutable reference RAI.

- Reasonable performance of algorithms implemented using RAI have not been demonstrated.

- Overlaps with the Index trait, which unlike RAI does have an expansion into mutable references.

- Does not give iterators any O(1) skip multiple steps forward/backward capabilities.

- The trait can be added again when we figure out the above points.

---

<div class="post-metadata">

**Author:** ![Gankra](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/gankra/32/6002_2.png) [@Gankra](https://internals.rust-lang.org/u/Gankra)\
**Post date:** [February 5, 2015, 9:09pm UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548/2 "2015-02-05T21:09:33Z")

</div>

Yeah a really useful RAI would need to provide unchecked options for efficient algorithm implementation, I think.

O(1) skip should be trivial to add backwards-compatibly with proper specialization support, though.

Also: Really disappointed you didn’t find a way to add an extra `I` to the accronym to shim in a “remove RAII” joke 😉

---

<div class="post-metadata">

**Author:** ![brson](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/brson/32/5197_2.png) [@brson](https://internals.rust-lang.org/u/brson)\
**Post date:** [February 5, 2015, 11:40pm UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548/3 "2015-02-05T23:40:18Z")

</div>

I’m in favor of removing this. Use cases have never been clear.

---

<div class="post-metadata">

**Author:** ![aturon](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/aturon/32/3272_2.png) [@aturon](https://internals.rust-lang.org/u/aturon)\
**Post date:** [February 6, 2015, 3:23am UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548/4 "2015-02-06T03:23:38Z")

</div>

Sounds good to me. We explicitly chose not to mark it `#[stable]` for several of the reasons you list.

---

<div class="post-metadata">

**Author:** ![bluss](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bluss/32/2264_2.png) [@bluss](https://internals.rust-lang.org/u/bluss)\
**Post date:** [February 6, 2015, 12:16pm UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548/5 "2015-02-06T12:16:39Z")

</div>

So maybe I shouldn’t be worried? I’m just worried that it will suddenly slip in for no reason at all.

Some other features are like that. Permutations/ElementSwaps in libstd are worrying.

- They allocate too much
- Cute algorithm but the lexical ordering is needed more often, .next\_permutation covers that in-place.

---

<div class="post-metadata">

**Author:** ![aturon](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/aturon/32/3272_2.png) [@aturon](https://internals.rust-lang.org/u/aturon)\
**Post date:** [February 7, 2015, 12:43am UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548/6 "2015-02-07T00:43:55Z")

</div>

> [@blake](#):
>
> So maybe I shouldn't be worried? I'm just worried that it will suddenly slip in for no reason at all.

Understood. I think this will get more clear over time. Right now we're stabilizing things we clearly need, deprecating/moving out things we clearly don't want (for now), and leaving the rest unstable.

In the long run, unstable items should be on a "path to stable" or else be removed. I think after the dust settles for 1.0 we'll re-evaluate the remaining unstable items under this metric.

> [@blake](#):
>
> Some other features are like that. Permutations/ElementSwaps in libstd are worrying.

Yep -- good eye! These were also specifically _not_ stabilized because they seem somewhat niche.

FWIW, these features could probably be moved out of tree before 1.0, it just hasn't been a core priority. If you wanted to put together an RFC/PR, I'd be glad to review. (It might be worth putting together a more comprehensive list of such APIs that we could reach consensus on beforehand.)

---

<div class="post-metadata">

**Author:** ![bluss](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bluss/32/2264_2.png) [@bluss](https://internals.rust-lang.org/u/bluss)\
**Post date:** [February 7, 2015, 9:41am UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548/7 "2015-02-07T09:41:58Z")

</div>

> [@aturon](#):
>
> Yep -- good eye! These were also specifically not stabilized because they seem somewhat niche.

I don't agree for permutations in general, just that this is not a good way to implement it.

---

<div class="post-metadata">

**Author:** ![bluss](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bluss/32/2264_2.png) [@bluss](https://internals.rust-lang.org/u/bluss)\
**Post date:** [March 25, 2019, 8:23am UTC](https://internals.rust-lang.org/t/pre-rfc-remove-randomaccessiterator/1548/8 "2019-03-25T08:23:51Z")

</div>

Closed on March 25, 2019, 8:23am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
