diff options
Diffstat (limited to 'macros/src/util/item_impl.rs')
-rw-r--r-- | macros/src/util/item_impl.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/macros/src/util/item_impl.rs b/macros/src/util/item_impl.rs new file mode 100644 index 0000000..271ae2f --- /dev/null +++ b/macros/src/util/item_impl.rs @@ -0,0 +1,20 @@ +use syn::{ImplItem, ImplItemMethod, ItemImpl}; + +pub fn find_impl_method_by_name<'item_impl>( + item_impl: &'item_impl ItemImpl, + method_name: &'static str, +) -> Option<&'item_impl ImplItemMethod> +{ + let impl_items = &item_impl.items; + + impl_items.iter().find_map(|impl_item| match impl_item { + ImplItem::Method(method_item) => { + if method_item.sig.ident == method_name { + Some(method_item) + } else { + None + } + } + &_ => None, + }) +} |