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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use Hash;
use Mutex;
use crateModuleDef;
use crate;
type Register = ;
/// A module built at runtime by a function, for integration crates. Its identity is the owner
/// type plus the configuration value, so these are still distinct Rust-typed identities.
///
/// ```
/// # use ulo::{DynamicModule, ModuleDef};
/// # #[derive(Clone, PartialEq, Eq, Hash)]
/// # struct RedisConfig;
/// # struct RedisIntegration;
/// # struct RedisPool;
/// # impl RedisPool {
/// # async fn connect(_: &RedisConfig) -> Self { RedisPool }
/// # }
/// pub fn redis_module(cfg: RedisConfig) -> DynamicModule {
/// DynamicModule::new::<RedisIntegration, _>(cfg.clone(), move |m| {
/// m.singleton(move || { let cfg = cfg.clone(); async move { RedisPool::connect(&cfg).await } });
/// m.export::<RedisPool>();
/// })
/// }
/// ```
///
/// The registration closure runs once: identities are deduplicated before `register` is called,
/// so a second import of an equal identity never reaches it.