diff options
author | HampusM <hampus@hampusmat.com> | 2022-07-31 17:27:33 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-08-01 15:26:43 +0200 |
commit | 7a6575220c6d9db564514bcbee552faa29095738 (patch) | |
tree | 19a97692bde26f994892830f0ff6f8cc23f611e1 /src/di_container.rs | |
parent | e20e442ee84918f8f06794ebb1a389a3a04bcdcc (diff) |
docs: add doc comments & deny missing docs
Diffstat (limited to 'src/di_container.rs')
-rw-r--r-- | src/di_container.rs | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/src/di_container.rs b/src/di_container.rs index e18fc3a..89bbcd1 100644 --- a/src/di_container.rs +++ b/src/di_container.rs @@ -1,3 +1,48 @@ +//! Dependency injection container and other related utilities. +/// +/// # Examples +/// ``` +/// use std::collections::HashMap; +/// +/// use syrette::{DIContainer, injectable}; +/// use syrette::errors::di_container::DIContainerError; +/// +/// trait IDatabaseService +/// { +/// fn get_all_records(&self, table_name: String) -> HashMap<String, String>; +/// } +/// +/// struct DatabaseService {} +/// +/// #[injectable(IDatabaseService)] +/// impl DatabaseService +/// { +/// fn new() -> Self +/// { +/// Self {} +/// } +/// } +/// +/// impl IDatabaseService for DatabaseService +/// { +/// fn get_all_records(&self, table_name: String) -> HashMap<String, String> +/// { +/// // Do stuff here +/// HashMap::<String, String>::new() +/// } +/// } +/// +/// fn main() -> error_stack::Result<(), DIContainerError> +/// { +/// let mut di_container = DIContainer::new(); +/// +/// di_container.bind::<dyn IDatabaseService>().to::<DatabaseService>(); +/// +/// let database_service = di_container.get::<dyn IDatabaseService>()?; +/// +/// Ok(()) +/// } +/// ``` use std::any::type_name; use std::marker::PhantomData; @@ -101,50 +146,6 @@ where } /// Dependency injection container. -/// -/// # Examples -/// ``` -/// use std::collections::HashMap; -/// -/// use syrette::{DIContainer, injectable}; -/// use syrette::errors::di_container::DIContainerError; -/// -/// trait IDatabaseService -/// { -/// fn get_all_records(&self, table_name: String) -> HashMap<String, String>; -/// } -/// -/// struct DatabaseService {} -/// -/// #[injectable(IDatabaseService)] -/// impl DatabaseService -/// { -/// fn new() -> Self -/// { -/// Self {} -/// } -/// } -/// -/// impl IDatabaseService for DatabaseService -/// { -/// fn get_all_records(&self, table_name: String) -> HashMap<String, String> -/// { -/// // Do stuff here -/// HashMap::<String, String>::new() -/// } -/// } -/// -/// fn main() -> error_stack::Result<(), DIContainerError> -/// { -/// let mut di_container = DIContainer::new(); -/// -/// di_container.bind::<dyn IDatabaseService>().to::<DatabaseService>(); -/// -/// let database_service = di_container.get::<dyn IDatabaseService>()?; -/// -/// Ok(()) -/// } -/// ``` pub struct DIContainer { bindings: DIContainerBindingMap, @@ -176,7 +177,7 @@ impl DIContainer /// - No binding for `Interface` exists /// - Resolving the binding for `Interface` fails /// - Casting the binding for `Interface` fails - /// - The binding for `Interface` is not injectable + /// - The binding for `Interface` is not transient pub fn get<Interface>( &self, ) -> error_stack::Result<TransientPtr<Interface>, DIContainerError> |