@@ -732,6 +732,17 @@ impl<'a> Iterator for Difference<'a> {
732732 }
733733}
734734
735+ impl < ' a > DoubleEndedIterator for Difference < ' a > {
736+ fn next_back ( & mut self ) -> Option < Self :: Item > {
737+ for nxt in self . iter . by_ref ( ) . rev ( ) {
738+ if !self . other . contains ( nxt) {
739+ return Some ( nxt) ;
740+ }
741+ }
742+ None
743+ }
744+ }
745+
735746// Difference will continue to return None once it first returns None.
736747impl < ' a > FusedIterator for Difference < ' a > { }
737748
@@ -756,6 +767,12 @@ impl<'a> Iterator for SymmetricDifference<'a> {
756767 }
757768}
758769
770+ impl < ' a > DoubleEndedIterator for SymmetricDifference < ' a > {
771+ fn next_back ( & mut self ) -> Option < Self :: Item > {
772+ self . iter . next_back ( )
773+ }
774+ }
775+
759776// SymmetricDifference will continue to return None once it first returns None.
760777impl < ' a > FusedIterator for SymmetricDifference < ' a > { }
761778
@@ -787,6 +804,17 @@ impl<'a> Iterator for Intersection<'a> {
787804 }
788805}
789806
807+ impl < ' a > DoubleEndedIterator for Intersection < ' a > {
808+ fn next_back ( & mut self ) -> Option < Self :: Item > {
809+ for nxt in self . iter . by_ref ( ) . rev ( ) {
810+ if self . other . contains ( nxt) {
811+ return Some ( nxt) ;
812+ }
813+ }
814+ None
815+ }
816+ }
817+
790818// Intersection will continue to return None once it first returns None.
791819impl < ' a > FusedIterator for Intersection < ' a > { }
792820
@@ -811,6 +839,12 @@ impl<'a> Iterator for Union<'a> {
811839 }
812840}
813841
842+ impl < ' a > DoubleEndedIterator for Union < ' a > {
843+ fn next_back ( & mut self ) -> Option < Self :: Item > {
844+ self . iter . next_back ( )
845+ }
846+ }
847+
814848// Union will continue to return None once it first returns None.
815849impl < ' a > FusedIterator for Union < ' a > { }
816850
0 commit comments