aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-21 19:42:12 +0200
committerHampusM <hampus@hampusmat.com>2022-08-21 19:42:12 +0200
commitda3f56d48f9c349b29e1d462b2a535b1a89c5e45 (patch)
tree35ae95f359507d9a4c1ba7fa9aa262e1c4cfd37f /macros/src/util
parent15e62b41bdde2791936c91c4f59a81368dd85d51 (diff)
refactor: improve private method names & clean up InjectableImpl
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;