gpt4 book ai didi

rust - 为什么我不能在 Split 上调用 next_back()?

转载 作者:行者123 更新时间:2023-11-29 08:04:36 26 4
gpt4 key购买 nike

<分区>

Split 的文档说它实现了 DoubleEndedIterator它应该有一个 next_back()获取最后一个元素的方法。

但是当我这样做的时候:

fn get_file_ext(file_name: &str) -> Option<String> {
if let Some(ext) = file_name.split(".").next_back() {
return Some(ext.to_owned());
}
None
}

我收到这个错误:

error[E0599]: no method named `next_back` found for struct `std::str::Split<'_, &str>` in the current scope
--> src/lib.rs:2:45
|
2 | if let Some(ext) = file_name.split(".").next_back() {
| ^^^^^^^^^ method not found in `std::str::Split<'_, &str>`
|
= note: the method `next_back` exists but the following trait bounds were not satisfied:
`std::str::pattern::StrSearcher<'_, '_>: std::str::pattern::DoubleEndedSearcher<'_>`
which is required by `std::str::Split<'_, &str>: std::iter::DoubleEndedIterator`

“未满足以下特征界限” 是什么意思?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com