aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/util')
-rw-r--r--macros/src/util/item_impl.rs20
-rw-r--r--macros/src/util/mod.rs1
2 files changed, 21 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,
+ })
+}
diff --git a/macros/src/util/mod.rs b/macros/src/util/mod.rs
index fe2fbbc..fc7b2c6 100644
--- a/macros/src/util/mod.rs
+++ b/macros/src/util/mod.rs
@@ -1 +1,2 @@
+pub mod item_impl;
pub mod iterator_ext;