From c501a5cc770f632eba1529de09bd3ae2d7958de6 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 22 Dec 2023 22:33:09 +0100 Subject: refactor: mock Dependency struct impl instead of IDependency --- macros/src/injectable/dependency.rs | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'macros/src/injectable/dependency.rs') diff --git a/macros/src/injectable/dependency.rs b/macros/src/injectable/dependency.rs index 8e22f21..30c156f 100644 --- a/macros/src/injectable/dependency.rs +++ b/macros/src/injectable/dependency.rs @@ -6,23 +6,6 @@ use crate::injectable::named_attr_input::NamedAttrInput; use crate::util::error::diagnostic_error_enum; use crate::util::syn_path::SynPathExt; -/// Interface for a dependency of a `Injectable`. -#[cfg_attr(test, mockall::automock)] -pub trait IDependency: Sized -{ - /// Build a new `Dependency` from a argument in a constructor method. - fn build(ctor_method_arg: &FnArg) -> Result; - - /// Returns the interface type. - fn get_interface(&self) -> &Type; - - /// Returns the pointer type identity. - fn get_ptr(&self) -> &Ident; - - /// Returns optional name of the dependency. - fn get_name(&self) -> &Option; -} - /// Representation of a dependency of a injectable type. /// /// Found as a argument in the constructor method of a `Injectable`. @@ -34,9 +17,11 @@ pub struct Dependency name: Option, } -impl IDependency for Dependency +#[cfg_attr(test, mockall::automock)] +impl Dependency { - fn build(ctor_method_arg: &FnArg) -> Result + /// Build a new `Dependency` from a argument in a constructor method. + pub fn build(ctor_method_arg: &FnArg) -> Result { let typed_ctor_method_arg = match ctor_method_arg { FnArg::Typed(typed_arg) => Ok(typed_arg), @@ -116,17 +101,23 @@ impl IDependency for Dependency }) } - fn get_interface(&self) -> &Type + /// Returns the dependency's interface type. + #[allow(dead_code)] // Mock function is never used + pub fn get_interface(&self) -> &Type { &self.interface } - fn get_ptr(&self) -> &Ident + /// Returns the dependency's pointer type name. + #[allow(dead_code)] // Mock function is never used + pub fn get_ptr(&self) -> &Ident { &self.ptr } - fn get_name(&self) -> &Option + /// Returns the dependency's name. + #[allow(dead_code)] // Mock function is never used + pub fn get_name(&self) -> &Option { &self.name } -- cgit v1.2.3-18-g5258