aboutsummaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-07-31 17:27:33 +0200
committerHampusM <hampus@hampusmat.com>2022-08-01 15:26:43 +0200
commit7a6575220c6d9db564514bcbee552faa29095738 (patch)
tree19a97692bde26f994892830f0ff6f8cc23f611e1 /macros
parente20e442ee84918f8f06794ebb1a389a3a04bcdcc (diff)
docs: add doc comments & deny missing docs
Diffstat (limited to 'macros')
-rw-r--r--macros/Cargo.toml2
-rw-r--r--macros/src/lib.rs76
2 files changed, 76 insertions, 2 deletions
diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index d806396..d9392e6 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -17,3 +17,5 @@ quote = "1.0.18"
proc-macro2 = "1.0.40"
uuid = { version = "0.8", features = ["v4"] }
+[dev_dependencies]
+syrette = { version = "0.2.0", path = "..", features = ["factory"] }
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 20eb7d3..aca4007 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -1,5 +1,8 @@
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
+#![deny(missing_docs)]
+
+//! Macros for the [Syrette](https://crates.io/crates/syrette) crate.
use proc_macro::TokenStream;
use quote::quote;
@@ -27,8 +30,26 @@ use libs::intertrait_macros::gen_caster::generate_caster;
///
/// # Important
/// If the interface trait argument is excluded, you should either manually
-/// declare the interface with the `declare_interface` macro or use
-/// the `di_container_bind` macro to create a DI container binding.
+/// declare the interface with the [`declare_interface!`] macro or use
+/// the [`di_container_bind`] macro to create a DI container binding.
+///
+/// # Example
+/// ```
+/// use syrette::injectable;
+///
+/// struct PasswordManager {}
+///
+/// #[injectable]
+/// impl PasswordManager {
+/// pub fn new() -> Self {
+/// Self {}
+/// }
+/// }
+/// ```
+///
+/// [`DIContainer`]: ../syrette/di_container/struct.DIContainer.html
+/// [`Injectable`]: ../syrette/interfaces/injectable/trait.Injectable.html
+/// [`di_container_bind`]: ../syrette/macro.di_container_bind.html
#[proc_macro_attribute]
pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenStream
{
@@ -62,6 +83,57 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
///
/// # Panics
/// If the attributed item is not a type alias.
+///
+/// # Examples
+/// ```
+/// use std::collections::HashMap;
+///
+/// use syrette::interfaces::factory::IFactory;
+/// use syrette::factory;
+///
+/// enum ConfigValue
+/// {
+/// String(String),
+/// Bool(bool),
+/// Int(i32),
+/// None,
+/// }
+///
+/// trait IConfigurator
+/// {
+/// fn configure(&self, key: String, value: ConfigValue);
+/// }
+///
+/// struct Configurator {
+/// config: HashMap<String, ConfigValue>,
+/// }
+///
+/// impl Configurator
+/// {
+/// fn new(keys: Vec<String>) -> Self
+/// {
+/// Self {
+/// config: HashMap::from(
+/// keys
+/// .iter()
+/// .map(|key| (key.clone(), ConfigValue::None))
+/// .collect::<HashMap<_, _>>()
+/// )
+/// }
+/// }
+/// }
+///
+/// impl IConfigurator for Configurator
+/// {
+/// fn configure(&self, key: String, value: ConfigValue)
+/// {
+/// // ...
+/// }
+/// }
+///
+/// #[factory]
+/// type IConfiguratorFactory = dyn IFactory<(Vec<String>,), dyn IConfigurator>;
+/// ```
#[proc_macro_attribute]
pub fn factory(_: TokenStream, type_alias_stream: TokenStream) -> TokenStream
{