aboutsummaryrefslogtreecommitdiff
path: root/macros/src/factory/build_declare_interfaces.rs
blob: 38dd35d5fd1ea9ec054febf3d48812208402f6df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use proc_macro2::TokenStream;
use quote::quote;

use crate::fn_trait::FnTrait;

pub fn build_declare_factory_interfaces(
    factory_interface: &FnTrait,
    is_threadsafe: bool,
) -> TokenStream
{
    if is_threadsafe {
        quote! {
            syrette::declare_interface!(
                syrette::private::castable_factory::threadsafe::ThreadsafeCastableFactory<
                    (std::sync::Arc<syrette::AsyncDIContainer>,),
                    #factory_interface
                > -> syrette::private::factory::IThreadsafeFactory<
                    (std::sync::Arc<syrette::AsyncDIContainer>,),
                    #factory_interface
                >,
                threadsafe_sharable = true
            );

            syrette::declare_interface!(
                syrette::private::castable_factory::threadsafe::ThreadsafeCastableFactory<
                    (std::sync::Arc<syrette::AsyncDIContainer>,),
                    #factory_interface
                > -> syrette::private::any_factory::AnyThreadsafeFactory,
                threadsafe_sharable = true
            );
        }
    } else {
        quote! {
            syrette::declare_interface!(
                syrette::private::castable_factory::blocking::CastableFactory<
                    #factory_interface,
                    syrette::di_container::blocking::DIContainer
                > -> syrette::private::factory::IFactory<
                    #factory_interface,
                    syrette::di_container::blocking::DIContainer
                >
            );

            syrette::declare_interface!(
                syrette::private::castable_factory::blocking::CastableFactory<
                    #factory_interface,
                    syrette::di_container::blocking::DIContainer
                > -> syrette::private::any_factory::AnyFactory
            );
        }
    }
}