# error\[E0507\]: cannot move out of indexed content

**URL:** <https://users.rust-lang.org/t/error-e0507-cannot-move-out-of-indexed-content/12815>\
**Category:** help\
**Created:** [September 10, 2017, 7:42pm UTC](https://users.rust-lang.org/t/error-e0507-cannot-move-out-of-indexed-content/12815 "2017-09-10T19:42:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![paholg](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/paholg/32/972_2.png) [@paholg](https://users.rust-lang.org/u/paholg)\
**Post date:** [September 10, 2017, 8:17pm UTC](https://users.rust-lang.org/t/error-e0507-cannot-move-out-of-indexed-content/12815/2 "2017-09-10T20:17:41Z")

</div>

In order to assign a string to `b`, you have to move it or copy it from where it was. You can't move it out of `a`, because that would be unsafe -- the string owned by `b` would then be pointing to somewhere inside `a`. So, your only option is to copy it out. Because `String` is non-`Copy`, you would have to clone it:

```rust
b = a[index as usize].clone();

```

By the way, a more idiomatic way to write that loop would be

```rust
for b in a {
    // do whatever with b
}

```

Or, if you still want access to the index,

```rust
for i in 0..a.len() {
    b = a[i].clone();
}

```

---

_[View the full topic](https://users.rust-lang.org/t/error-e0507-cannot-move-out-of-indexed-content/12815)._
