chunkmd: say rfind, which is what this was doing

This commit is contained in:
funkpower
2026-09-19 17:36:18 -04:00
parent e811a4d724
commit a80f8a024d
+3 -2
View File
@@ -179,9 +179,11 @@ impl<'a> ChapterIndex<'a> {
/// per page in every chapter's span: a single mistyped marker reading /// per page in every chapter's span: a single mistyped marker reading
/// `<!-- Page 20231115 -->` would ask for a gigabyte of them. /// `<!-- Page 20231115 -->` would ask for a gigabyte of them.
pub fn chapter_of_page(chapters: &[Chapter], page: u32) -> Option<&str> { pub fn chapter_of_page(chapters: &[Chapter], page: u32) -> Option<&str> {
// The last chapter that covers the page, not the first: chapters can
// nest, and the innermost one is the one a reader would name.
chapters chapters
.iter() .iter()
.filter(|chapter| { .rfind(|chapter| {
let Some(start) = chapter.start_page else { let Some(start) = chapter.start_page else {
return false; return false;
}; };
@@ -193,7 +195,6 @@ pub fn chapter_of_page(chapters: &[Chapter], page: u32) -> Option<&str> {
}; };
(start..=end.max(start)).contains(&page) && end >= start (start..=end.max(start)).contains(&page) && end >= start
}) })
.next_back()
.map(|chapter| chapter.title.as_str()) .map(|chapter| chapter.title.as_str())
} }