The documentation for Split
says that it implements DoubleEndedIterator
which is supposed to have a next_back()
method which gets the last element.
But when I do this:
fn get_file_ext(file_name: &str) -> Option<String> {
if let Some(ext) = file_name.split(".").next_back() {
return Some(ext.to_owned());
}
None
}
I get this error:
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`
What does it mean by "the following trait bounds were not satisfied"
?
` means? Are the `<>` syntactical sugar or do they have a meaning?
– financial_physician Mar 17 '22 at 20:39