aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-07-19 23:01:02 +0200
committerHampusM <hampus@hampusmat.com>2022-07-19 23:01:02 +0200
commit21726f29fd1020195fb52db6f568333bcfdb185c (patch)
treeeca9ed707689f8912677f2e7607be4f06bc78b18
parent9ab2f550a25c3e4465afa025e4ffb1294b331bdb (diff)
docs: improve and clean up doc comment examples
-rw-r--r--syrette/src/di_container.rs41
-rw-r--r--syrette_macros/src/lib.rs84
2 files changed, 41 insertions, 84 deletions
diff --git a/syrette/src/di_container.rs b/syrette/src/di_container.rs
index df51140..334c533 100644
--- a/syrette/src/di_container.rs
+++ b/syrette/src/di_container.rs
@@ -74,9 +74,46 @@ where
///
/// # Examples
/// ```
-/// di_container.bind::<dyn IDatabaseService>().to::<DatabaseService>();
+/// use std::collections::HashMap;
///
-/// let database_service = di_container.get::<dyn IDatabaseService>()?;
+/// 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
{
diff --git a/syrette_macros/src/lib.rs b/syrette_macros/src/lib.rs
index 2981ea7..ed1a509 100644
--- a/syrette_macros/src/lib.rs
+++ b/syrette_macros/src/lib.rs
@@ -20,43 +20,10 @@ use libs::intertrait_macros::gen_caster::generate_caster;
/// Makes a struct injectable. Thereby usable with `DIContainer`.
///
/// # Arguments
-///
/// * A interface trait the struct implements.
///
/// # Panics
/// If the attributed item is not a impl.
-///
-/// # Examples
-/// ```
-/// trait IConfigReader
-/// {
-/// fn read_config(&self) -> Config;
-/// }
-///
-/// struct ConfigReader
-/// {
-/// _file_reader: InterfacePtr<IFileReader>,
-/// }
-///
-/// impl ConfigReader
-/// {
-/// fn new(file_reader: InterfacePtr<IFileReader>) -> Self
-/// {
-/// Self {
-/// _file_reader: file_reader
-/// }
-/// }
-/// }
-///
-/// #[injectable(IConfigReader)]
-/// impl IConfigReader for ConfigReader
-/// {
-/// fn read_config(&self) -> Config
-/// {
-/// // Stuff here
-/// }
-/// }
-/// ```
#[proc_macro_attribute]
pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenStream
{
@@ -82,47 +49,6 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
///
/// # Panics
/// If the attributed item is not a type alias.
-///
-/// # Examples
-/// ```
-/// trait IUser
-/// {
-/// fn name(&self) -> String;
-/// fn age(&self) -> i32;
-/// }
-///
-/// struct User
-/// {
-/// _name: String,
-/// _age: i32,
-/// }
-///
-/// impl User
-/// {
-/// fn new(name: String, age: i32) -> Self
-/// {
-/// Self {
-/// _name: name,
-/// _age: age,
-/// }
-/// }
-/// }
-///
-/// impl IUser for User
-/// {
-/// fn name(&self) -> String
-/// {
-/// self._name
-/// }
-///
-/// fn age(&self) -> i32
-/// {
-/// self._age
-/// }
-/// }
-///
-/// type UserFactory = dyn IFactory<(String, i32), dyn IUser>;
-/// ```
#[proc_macro_attribute]
pub fn factory(_: TokenStream, type_alias_stream: TokenStream) -> TokenStream
{
@@ -155,14 +81,8 @@ pub fn factory(_: TokenStream, type_alias_stream: TokenStream) -> TokenStream
/// Declares the interface trait of a implementation.
///
-/// # Examples
-/// ```
-/// declare_interface!(ClientService -> IClientService);
-///
-/// ```
-///
-/// With `ClientService` in this case being the concrete
-/// implementation and `IClientService` being the interface trait.
+/// # Arguments
+/// {Implementation} -> {Interface}
///
#[proc_macro]
pub fn declare_interface(input: TokenStream) -> TokenStream