From cf1594cf43e23c9fc8f74cf69e22f81227e82f2b Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Tue, 15 Nov 2022 16:53:44 +0000 Subject: [PATCH] git-ref-format: DoubleEndedIterator for Components Add DoubleEndedIterator implementations for the two Components iterators. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- git-ref-format/core/src/name/iter.rs | 11 +++++++++++ git-ref-format/core/src/refspec/iter.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/git-ref-format/core/src/name/iter.rs b/git-ref-format/core/src/name/iter.rs index de14c5f..e51e050 100644 --- a/git-ref-format/core/src/name/iter.rs +++ b/git-ref-format/core/src/name/iter.rs @@ -34,6 +34,17 @@ impl<'a> Iterator for Components<'a> { } } +impl<'a> DoubleEndedIterator for Components<'a> { + #[inline] + fn next_back(&mut self) -> Option { + self.inner + .next_back() + .map(RefStr::from_str) + .map(Cow::from) + .map(Component) + } +} + impl<'a> From<&'a RefStr> for Components<'a> { #[inline] fn from(rs: &'a RefStr) -> Self { diff --git a/git-ref-format/core/src/refspec/iter.rs b/git-ref-format/core/src/refspec/iter.rs index 3ab8a2c..a5daf1c 100644 --- a/git-ref-format/core/src/refspec/iter.rs +++ b/git-ref-format/core/src/refspec/iter.rs @@ -66,6 +66,17 @@ impl<'a> Iterator for Components<'a> { } } +impl<'a> DoubleEndedIterator for Components<'a> { + #[inline] + fn next_back(&mut self) -> Option { + self.inner.next_back().map(|next| match next { + "*" => Component::Glob(None), + x if x.contains('*') => Component::Glob(Some(PatternStr::from_str(x))), + x => Component::Normal(RefStr::from_str(x)), + }) + } +} + impl<'a> From<&'a PatternStr> for Components<'a> { #[inline] fn from(p: &'a PatternStr) -> Self {