| 777 | C: Comparator<K>, |
| 778 | { |
| 779 | fn next_back(&mut self) -> Option<Self::Item> { |
| 780 | let old_direction = mem::replace(&mut self.direction, Direction::NextBack); |
| 781 | |
| 782 | let key_val = (|| { |
| 783 | if old_direction == Direction::NextBack { |
| 784 | self.cursor.prev() |
| 785 | } else { |
| 786 | match self.end { |
| 787 | Bound::Included(k) => match self.cursor.goto(k) { |
| 788 | Some(_) => Some((self.cursor.key()?, self.cursor.value()?)), |
| 789 | None => self.cursor.prev(), |
| 790 | }, |
| 791 | Bound::Excluded(k) => { |
| 792 | self.cursor.goto(k); |
| 793 | if self |
| 794 | .cursor |
| 795 | .key() |
| 796 | .is_some_and(|key| self.cursor.comp.cmp(k, key).is_eq()) |
| 797 | { |
| 798 | self.cursor.prev() |
| 799 | } else { |
| 800 | Some((self.cursor.key()?, self.cursor.value()?)) |
| 801 | } |
| 802 | } |
| 803 | Bound::Unbounded => { |
| 804 | self.cursor.goto_end(); |
| 805 | self.cursor.prev() |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | })(); |
| 810 | |
| 811 | match key_val { |
| 812 | Some((key, val)) if self.is_in_bounds(key) => { |
| 813 | self.end = Bound::Excluded(key); |
| 814 | Some((key, val)) |
| 815 | } |
| 816 | _ => { |
| 817 | self.cursor.goto_end(); |
| 818 | None |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | impl<'a, K, V, C> MapRange<'a, K, V, C> |