diff options
author | HampusM <hampus@hampusmat.com> | 2023-12-22 22:33:09 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-12-22 22:33:09 +0100 |
commit | c501a5cc770f632eba1529de09bd3ae2d7958de6 (patch) | |
tree | e45333f7bf71ae17cf2016616ddf339a690bf8db /macros/src/injectable/dependency.rs | |
parent | c56d6fee4835ca103d1e4e5fd7e9e3913c7ed6ba (diff) |
refactor: mock Dependency struct impl instead of IDependency
Diffstat (limited to 'macros/src/injectable/dependency.rs')
-rw-r--r-- | macros/src/injectable/dependency.rs | 35 |
1 files changed, 13 insertions, 22 deletions
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<Self, DependencyError>; - - /// 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<LitStr>; -} - /// 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<LitStr>, } -impl IDependency for Dependency +#[cfg_attr(test, mockall::automock)] +impl Dependency { - fn build(ctor_method_arg: &FnArg) -> Result<Self, DependencyError> + /// Build a new `Dependency` from a argument in a constructor method. + pub fn build(ctor_method_arg: &FnArg) -> Result<Self, DependencyError> { 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<LitStr> + /// Returns the dependency's name. + #[allow(dead_code)] // Mock function is never used + pub fn get_name(&self) -> &Option<LitStr> { &self.name } |