bon_macros/util/
punctuated.rsuse crate::util::prelude::*;
use syn::punctuated::Punctuated;
pub(crate) trait PunctuatedExt<T, P> {
fn try_retain_mut(&mut self, f: impl FnMut(&mut T) -> Result<bool>) -> Result;
}
impl<T, P> PunctuatedExt<T, P> for Punctuated<T, P>
where
P: Default,
{
fn try_retain_mut(&mut self, mut try_predicate: impl FnMut(&mut T) -> Result<bool>) -> Result {
for mut pair in std::mem::take(self).into_pairs() {
if try_predicate(pair.value_mut())? {
self.extend([pair]);
}
}
Ok(())
}
}