aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util/item_impl.rs
blob: 621f6be4fb81d9b8979b3969f6fdeac30573c8eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use proc_macro2::Ident;
use syn::{ImplItem, ImplItemMethod, ItemImpl};

pub fn find_impl_method_by_name_mut<'item_impl>(
    item_impl: &'item_impl mut ItemImpl,
    method_name: &Ident,
) -> Option<&'item_impl mut ImplItemMethod>
{
    let impl_items = &mut item_impl.items;

    impl_items.iter_mut().find_map(|impl_item| match impl_item {
        ImplItem::Method(method_item) => {
            if &method_item.sig.ident == method_name {
                Some(method_item)
            } else {
                None
            }
        }
        &mut _ => None,
    })
}