根据
Split
文档,对于在字符串上执行split
操作的结果也有一个rev
方法:fn main() {
let mut length = 0;
let mut mult = 1;
for part in "1:30".split(":").rev() {
length += mult * part.parse::<i32>().unwrap();
mult *= 60;
}
}
我遇到了以下错误:
error[E0277]: the trait bound `std::str::pattern::StrSearcher<'_, '_>: std::str::pattern::DoubleEndedSearcher<'_>` is not satisfied
--> src/main.rs:4:35
|
4 | for part in "1:30".split(":").rev() {
| ^^^ the trait `std::str::pattern::DoubleEndedSearcher<'_>` is not implemented for `std::str::pattern::StrSearcher<'_, '_>`
|
= note: required because of the requirements on the impl of `std::iter::DoubleEndedIterator` for `std::str::Split<'_, &str>`
error[E0277]: the trait bound `std::str::pattern::StrSearcher<'_, '_>: std::str::pattern::DoubleEndedSearcher<'_>` is not satisfied
--> src/main.rs:4:17
|
4 | for part in "1:30".split(":").rev() {
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::str::pattern::DoubleEndedSearcher<'_>` is not implemented for `std::str::pattern::StrSearcher<'_, '_>`
|
= note: required because of the requirements on the impl of `std::iter::DoubleEndedIterator` for `std::str::Split<'_, &str>`
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::iter::Rev<std::str::Split<'_, &str>>`
str
需要实现DoubleEndedSearcher
,而是在这种情况下需要实现的是StrSearcher
。我想是这样的。或者我对str
上的Pattern
实现理解有误... - DK.