diff options
author | HampusM <hampus@hampusmat.com> | 2022-08-28 13:50:15 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-08-28 13:50:15 +0200 |
commit | 6e31d8f9e46fece348f329763b39b9c6f2741c07 (patch) | |
tree | 1993cd9af613ffe7dcb9a88fcca7f0dbfb28b67b | |
parent | f91c4ce73786a69e4ec72f69ef4d9d5f03ac5886 (diff) |
docs: improve & add examples
-rw-r--r-- | macros/src/lib.rs | 77 | ||||
-rw-r--r-- | src/lib.rs | 32 |
2 files changed, 58 insertions, 51 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 6e3fc0a..eb3a2be 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -70,7 +70,6 @@ use libs::intertrait_macros::gen_caster::generate_caster; /// { /// pub fn new( /// #[named("tough")] tough_armor: TransientPtr<dyn IArmor>, -/// /// #[named("light")] light_armor: TransientPtr<dyn IArmor>, /// ) -> Self /// { @@ -145,51 +144,23 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt /// /// # Examples /// ``` -/// use std::collections::HashMap; -/// -/// use syrette::factory; -/// use syrette::interfaces::factory::IFactory; -/// -/// 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) -/// { -/// // ... -/// } -/// } -/// +/// # use syrette::factory; +/// # use syrette::interfaces::factory::IFactory; +/// # +/// # trait IConfigurator {} +/// # +/// # struct Configurator {} +/// # +/// # impl Configurator +/// # { +/// # fn new() -> Self +/// # { +/// # Self {} +/// # } +/// # } +/// # +/// # impl IConfigurator for Configurator {} +/// # /// #[factory] /// type IConfiguratorFactory = dyn IFactory<(Vec<String>,), dyn IConfigurator>; /// ``` @@ -228,6 +199,19 @@ pub fn factory(_: TokenStream, type_alias_stream: TokenStream) -> TokenStream /// /// # Arguments /// {Implementation} -> {Interface} +/// +/// # Examples +/// ``` +/// # use syrette::declare_interface; +/// # +/// # trait INinja {} +/// # +/// # struct Ninja {} +/// # +/// # impl INinja for Ninja {} +/// # +/// declare_interface!(Ninja -> INinja); +/// ``` #[proc_macro] pub fn declare_interface(input: TokenStream) -> TokenStream { @@ -267,7 +251,6 @@ pub fn declare_interface(input: TokenStream) -> TokenStream /// { /// pub fn new( /// #[syrette::named("strong")] strong_weapon: TransientPtr<dyn IWeapon>, -/// /// #[syrette::named("weak")] weak_weapon: TransientPtr<dyn IWeapon>, /// ) -> Self /// { @@ -38,6 +38,30 @@ mod provider; /// /// # Arguments /// {interface} => {implementation}, {DI container variable name} +/// +/// # Examples +/// ``` +/// # use syrette::{di_container_bind, DIContainer, injectable}; +/// # +/// # trait INinja {} +/// # +/// # struct Ninja {} +/// # +/// # #[injectable] +/// # impl Ninja +/// # { +/// # fn new() -> Self +/// # { +/// # Self {} +/// # } +/// # } +/// # +/// # impl INinja for Ninja {} +/// # +/// let mut di_container = DIContainer::new(); +/// +/// di_container_bind!(INinja => Ninja, di_container); +/// ``` #[macro_export] macro_rules! di_container_bind { ($interface: path => $implementation: ty, $di_container: ident) => { @@ -62,8 +86,8 @@ macro_rules! di_container_bind { /// /// # Examples /// ``` -/// use syrette::declare_default_factory; -/// +/// # use syrette::declare_default_factory; +/// # /// trait IParser /// { /// // Methods and etc here... @@ -75,8 +99,8 @@ macro_rules! di_container_bind { /// The expanded equivelent of this would be /// /// ``` -/// use syrette::declare_default_factory; -/// +/// # use syrette::declare_default_factory; +/// # /// trait IParser { /// // Methods and etc here... /// } |