Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以编程方式在Rust上创建字符串切片_Rust - Fatal编程技术网

以编程方式在Rust上创建字符串切片

以编程方式在Rust上创建字符串切片,rust,Rust,有一个对象只接受和[&str]作为输入,但我需要动态生成这个列表。我尝试了很多方法,但总是出错 我的代码: 使用std::fs; fn示例(){ let path=fs::read_dir(“./”).unwrap(); 让mut input_files=Vec:::new(); 对于路径中的路径{ 设x=[“./”,path.unwrap().path().to_str().unwrap()] .concat() .as_str(); 输入_文件。推送(x); } } 错误: 错误[E071

有一个对象只接受
和[&str]
作为输入,但我需要动态生成这个列表。我尝试了很多方法,但总是出错

我的代码:

使用std::fs;
fn示例(){
let path=fs::read_dir(“./”).unwrap();
让mut input_files=Vec:::new();
对于路径中的路径{
设x=[“./”,path.unwrap().path().to_str().unwrap()]
.concat()
.as_str();
输入_文件。推送(x);
}
}
错误:

错误[E0716]:借用时丢弃的临时值
-->src/lib.rs:8:17
|
8 |设x=[“./”,path.unwrap().path().to_str().unwrap()]
|  _________________^
9 | | concat()
||uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu^创建一个临时文件,该文件在仍在使用时被释放
10.as|u str();
|-在此语句末尾释放临时值
11 |输入_文件。推送(x);
|-借用,以后在这里使用
|
=注意:考虑使用一个“让”绑定来创建一个较长的生命值
我认为这个错误是因为
concat
创建了一个临时文件,但是为什么呢?为什么它不能返回字符串,我应该如何修复它


我不能使用
String

tl;DrimeDebug:也考虑和@ TrutCL,但我需要将一段和STR 传递给对象。如果我使用
Vec
,我该怎么做?。。