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

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:

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 if needed :slight_smile:

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

1 Like