From 43e0bdb4cc598f199eacb63f755f30dc2108146b Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 18 Mar 2023 18:26:53 +0100 Subject: feat: parse impl in mock macro as actual impl block --- macros/src/mock.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'macros/src/mock.rs') diff --git a/macros/src/mock.rs b/macros/src/mock.rs index 88d3434..1b6dd67 100644 --- a/macros/src/mock.rs +++ b/macros/src/mock.rs @@ -16,7 +16,6 @@ use syn::{ ReturnType, Signature, Token, - TraitItemMethod, Type, TypePath, TypeReference, @@ -43,18 +42,15 @@ use crate::util::create_unit_type_tuple; pub struct Mock { ident: Ident, - mocked_trait: TypePath, + mocked_trait: Path, expectations_fields: Vec, - item_methods: Vec, + item_methods: Vec, } impl Mock { - pub fn new( - ident: Ident, - mocked_trait: TypePath, - item_methods: &[TraitItemMethod], - ) -> Self + pub fn new(ident: Ident, mocked_trait: Path, item_methods: &[ImplItemMethod]) + -> Self { let expectations_fields = item_methods .iter() @@ -179,7 +175,7 @@ impl ToTokens for ExpectationsField } } -fn create_mock_function(item_method: TraitItemMethod) -> ImplItemMethod +fn create_mock_function(item_method: ImplItemMethod) -> ImplItemMethod { let func_ident = &item_method.sig.ident; @@ -247,7 +243,7 @@ fn create_mock_function(item_method: TraitItemMethod) -> ImplItemMethod } } -fn create_expect_function(mock: &Ident, item_method: &TraitItemMethod) -> ImplItemMethod +fn create_expect_function(mock: &Ident, item_method: &ImplItemMethod) -> ImplItemMethod { let signature = Signature::new( format_ident!("expect_{}", item_method.sig.ident), -- cgit v1.2.3-18-g5258