pub(crate) fn collect_manual_serde_type_names(items: &[syn::Item]) -> ahash::AHashSet<String> {
let mut has_serialize: ahash::AHashSet<String> = ahash::AHashSet::new();
let mut has_deserialize: ahash::AHashSet<String> = ahash::AHashSet::new();
for item in items {
if let syn::Item::Impl(item_impl) = item {
let Some((_, trait_path, _)) = &item_impl.trait_ else {
continue;
};
let type_name = match &*item_impl.self_ty {
syn::Type::Path(p) => p.path.segments.last().map(|s| s.ident.to_string()),
_ => None,
};
let Some(type_name) = type_name else {
continue;
};
let trait_last = trait_path.segments.last().map(|s| s.ident.to_string());
match trait_last.as_deref() {
Some("Serialize") => {
has_serialize.insert(type_name);
}
Some("Deserialize") => {
has_deserialize.insert(type_name);
}
_ => {}
}
}
}
has_serialize
.into_iter()
.filter(|name| has_deserialize.contains(name))
.collect()
}