rust - vec 拼接预期字符串找到 &str
问题描述
我正在尝试向 vec 添加几个条目,但我不断收到不匹配的类型:
pub fn create_lib_file(name: &str, targets: Vec<&str>) -> String {
let mut my_vec = vec![
"[lib]",
"",
"",
"[files]",
"",
"",
"[general]",
"",
];
// The targets are just strings passed from the CLI command.
for t in targets {
match t {
"one" => {
let file_name = format!("user/test/{}.dll", name);
let slice = &[file_name];
my_vec.splice(2..2, slice.iter().cloned());
}
}
}
return my_vec.join("\n");
}
这给了我一个错误:
error[E0271]: type mismatch resolving `<std::slice::Iter<'_, std::string::String> as std::iter::Iterator>::Item == &&str`
--> src/lib.rs:19:24
|
19 | my_vec.splice(2..2, slice.iter().cloned());
| ^^^^^^ expected struct `std::string::String`, found `&str`
|
= note: expected reference `&std::string::String`
found reference `&&str`
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::iter::Cloned<std::slice::Iter<'_, std::string::String>>`
我认为这与file_name
我尝试使用的有关to_owned()
,to_string()
但到目前为止我没有尝试将其转换file_name
为String
有效。
解决方案
推荐阅读
- reactjs - 提交时反应/挂钩额外的未定义字段
- r - 如何让折线图中的每一年都有不同的颜色
- cmd - CMD 将所有文件跨任何子文件夹移动到现有级别并删除子文件夹
- c# - Microsoft Graph API 自定义列未显示在项目字段中
- mysql - 使用“键集分页”重置计数
- python-3.x - python-plotly 在同一图中具有相同 Y 轴的多条线
- javascript - 状态更新时重新渲染反应组件
- javascript - 地图图层在初始加载后不会再次渲染
- css - 为什么 div 标签没有通过其 className 更改 css?
- asio - 有没有我可以学习的教程来了解 Steinberg ASIO SDK?