string - 我可以直接从拆分中获取字符串吗?
问题描述
这段代码:
fn main() {
let input = String::from("The quick brown fox");
for s in input.split(" ") {
let s2: String = s;
println!("{:?}", s2)
}
}
给我这个错误:
error[E0308]: mismatched types
--> src\main.rs:8:26
|
8 | let s2: String = s;
| ------ ^
| | |
| | expected struct `std::string::String`, found `&str`
| | help: try using a conversion method: `s.to_string()`
| expected due to this
我是否必须按照编译器的建议进行操作(s
在循环内进行转换),或者我可以更改循环以便String
直接从拆分中获得 s 吗?
解决方案
推荐阅读
- javascript - 借助扩展运算符修改对象的属性导致原始对象被修改?
- python - 使用 tf.data 的 One-hot 编码混合了列
- broadleaf-commerce - 在管理员中显示子属性对象列表网格
- javascript - React Native,选择时如何更改TextInputField的BottomborderColor?
- android - Razorpay 错误“合作伙伴凭据需要帐户 ID”
- mysql - ERR_HTTP_HEADERS_SENT]:发送到客户端后无法设置标头
- go - 在 Go 中将时间戳从一种有效的 RFC3339 格式转换为另一种格式
- sql - 将 SQL 数据从备份表复制到其他表
- python - 地址栏显示数据:,同时尝试通过 Selenium 和 Python 使用 ChromeDriver Chrome 进行抓取
- python - 使用正则表达式组更新 python 字典