我需要拆分另一个String(不&str)String:
use std::str::Split;
fn main() {
let x = "".to_string().split("".to_string());
}
Run Code Online (Sandbox Code Playgroud)
为什么我会遇到此错误以及如果我必须对字符串进行操作,如何避免它?
error[E0277]: the trait bound `std::string::String: std::ops::FnMut<(char,)>` is not satisfied
--> src/main.rs:4:32
|
4 | let x = "".to_string().split("".to_string());
| ^^^^^ the trait `std::ops::FnMut<(char,)>` is not implemented for `std::string::String`
|
= note: required because of the requirements on the impl of `std::str::pattern::Pattern<'_>` for `std::string::String`
Run Code Online (Sandbox Code Playgroud)
根据# Derefstix- beginners IRC频道,这可能是1.20.0-夜间失败的一个例子.如何在Rust中拆分字符串?不按地址分割的问题String,不是&str.
一切都在文档中.您可以提供以下其中一项:
&str,char,这三种类型实现了Pattern特征.您都给人一种String来split代替&str.
例:
fn main() {
let x = "".to_string();
let split = x.split("");
}
Run Code Online (Sandbox Code Playgroud)