use syn::parse::Error; use syn::spanned::Spanned; /// Return the value that fulfills the predicate if there is one in the slice. Panic if there is /// more than one. pub fn find_only(iter: impl Iterator, pred: F) -> Result, Error> where T: Spanned, F: Fn(&T) -> Result, { let mut result = None; for item in iter { if pred(&item)? { if result.is_some() { return Err(Error::new(item.span(), "Multiple defaults")); } result = Some(item); } } Ok(result) }