Rust 如何将值从一个列表移动/克隆到另一个列表?

Rust 如何将值从一个列表移动/克隆到另一个列表?,rust,Rust,我只是想做一些像这样的事情: fn main() { let mut points : Vec<(&str, &str)> = Vec::new(); let existing : Vec<(String, String)> = Vec::new(); for t in existing { points.push((&t.0[..], &t.1[..])); } } 我怎么能在铁锈里做这个

我只是想做一些像这样的事情:

fn main() {
    let mut points : Vec<(&str, &str)> = Vec::new();
    let existing : Vec<(String, String)> = Vec::new();

    for t in existing {
      points.push((&t.0[..], &t.1[..]));
    }
}
我怎么能在铁锈里做这个


谢谢

生命周期从变量声明开始。由于
变量是在
现有
变量之前创建的,
不允许有任何对
现有
的引用,因为
现有
将在
之前删除

第二个问题是对值进行迭代,这将进一步限制循环体中字符串的生存期

简单的解决方案是交换两个声明,并将循环更改为迭代引用而不是值:

let existing : Vec<(String, String)> = Vec::new();
let mut points : Vec<(&str, &str)> = Vec::new();

for t in &existing {
    points.push((&t.0, &t.1));
}
let existing:Vec=Vec::new();
让mut指向:Vec=Vec::new();
对于现有和现有的t{
点。推送(&t.0和&t.1));
}

生命周期从变量声明开始。由于
变量是在
现有
变量之前创建的,
不允许有任何对
现有
的引用,因为
现有
将在
之前删除

第二个问题是对值进行迭代,这将进一步限制循环体中字符串的生存期

简单的解决方案是交换两个声明,并将循环更改为迭代引用而不是值:

let existing : Vec<(String, String)> = Vec::new();
let mut points : Vec<(&str, &str)> = Vec::new();

for t in &existing {
    points.push((&t.0, &t.1));
}
let existing:Vec=Vec::new();
让mut指向:Vec=Vec::new();
对于现有和现有的t{
点。推送(&t.0和&t.1));
}