# How to properly move ownership in an inner loop in Rust?

**URL:** <https://internals.rust-lang.org/t/how-to-properly-move-ownership-in-an-inner-loop-in-rust/14696>\
**Category:** guidelines\
**Created:** [May 13, 2021, 8:04am UTC](https://internals.rust-lang.org/t/how-to-properly-move-ownership-in-an-inner-loop-in-rust/14696 "2021-05-13T08:04:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![An7One](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/an7one/32/7468_2.png) [@An7One](https://internals.rust-lang.org/u/An7One)\
**Post date:** [May 13, 2021, 8:04am UTC](https://internals.rust-lang.org/t/how-to-properly-move-ownership-in-an-inner-loop-in-rust/14696/1 "2021-05-13T08:04:16Z")

</div>

How to properly move ownership of the data, in an inner loop, so that once the final iteration gets done, the container iterated will be `Drop()` ed.

For example:

```rust
let left_strs: Vec<String> = Self::allowed(&slice[..i]);
let right_strs: Vec<String> = Self::allowed(&slice[i..]);
for left_str in left_strs{
    // how to properly move the ownership of the data here?
    for right_str in right_strs.iter(){
        ans.push(format!("({}, {})", left_str, right_str));
    }
}

```

Welcome to answer this question in the [Stackoverflow](https://stackoverflow.com/questions/67515857/how-to-properly-move-ownership-in-an-inner-loop-in-rust) if needed 🙂

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [May 13, 2021, 8:17am UTC](https://internals.rust-lang.org/t/how-to-properly-move-ownership-in-an-inner-loop-in-rust/14696/2 "2021-05-13T08:17:39Z")

</div>

It seems like you found the wrong forum. This “internals” forum is about the language design of Rust and the compiler/tooling implementation (and related topics). For questions for help in _using_ Rust, please go to [users.rust-lang.org](http://users.rust-lang.org).

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [August 11, 2021, 8:18am UTC](https://internals.rust-lang.org/t/how-to-properly-move-ownership-in-an-inner-loop-in-rust/14696/3 "2021-08-11T08:18:13Z")

</div>

Closed on August 11, 2021, 8:18am UTC

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