1use crate::util::prelude::*;
2use syn::punctuated::Punctuated;
34pub(crate) trait PunctuatedExt<T, P> {
5/// Remove all alements from the [`Punctuated`] that do not satisfy the predicate.
6 /// Also bail on the first error that the predicate returns.
7fn try_retain_mut(&mut self, f: impl FnMut(&mut T) -> Result<bool>) -> Result;
8}
910impl<T, P> PunctuatedExt<T, P> for Punctuated<T, P>
11where
12P: Default,
13{
14fn try_retain_mut(&mut self, mut try_predicate: impl FnMut(&mut T) -> Result<bool>) -> Result {
15// Unforunatelly, there is no builtin `retain` or `remove` in `Punctuated`
16 // so we just re-create it from scratch.
17for mut pair in std::mem::take(self).into_pairs() {
18if try_predicate(pair.value_mut())? {
19self.extend([pair]);
20 }
21 }
22Ok(())
23 }
24}