Skip to main content

component_map/
lib.rs

1use derive_more::Constructor;
2use std::collections::HashMap;
3
4mod async_fallible;
5mod async_infallible;
6mod sync_fallible;
7mod sync_infallible;
8
9#[derive(Debug, Constructor)]
10pub struct Keyed<Key, Value> {
11    key: Key,
12    value: Value,
13}
14
15#[derive(Debug, Constructor)]
16pub struct WithArgs<Args, Comp> {
17    pub component: Comp,
18    pub args: Args,
19}
20
21#[derive(Debug, Constructor)]
22pub struct ComponentMap<Key, Args, Comp, FnInit> {
23    map: HashMap<Key, WithArgs<Args, Comp>>,
24    init: FnInit,
25}
26
27impl<Key, Args, Comp, FnInit> ComponentMap<Key, Args, Comp, FnInit> {
28    pub fn components(&self) -> &HashMap<Key, WithArgs<Args, Comp>> {
29        &self.map
30    }
31
32    pub fn components_mut(&mut self) -> &mut HashMap<Key, WithArgs<Args, Comp>> {
33        &mut self.map
34    }
35
36    pub fn fn_init(&self) -> &FnInit {
37        &self.init
38    }
39}