initiative_core/app/
meta.rs1use super::{CommandAlias, Event};
2use crate::storage::{DataStore, Repository};
3use crate::world;
4use rand::prelude::*;
5use std::collections::HashSet;
6use std::fmt;
7
8pub struct AppMeta {
9 pub command_aliases: HashSet<CommandAlias>,
10 pub demographics: world::Demographics,
11 pub event_dispatcher: &'static dyn Fn(Event),
12 pub rng: SmallRng,
13 pub repository: Repository,
14}
15
16impl AppMeta {
17 pub fn new<F: Fn(Event)>(
18 data_store: impl DataStore + 'static,
19 event_dispatcher: &'static F,
20 ) -> Self {
21 Self {
22 command_aliases: HashSet::default(),
23 demographics: world::Demographics::default(),
24 event_dispatcher,
25 repository: Repository::new(data_store),
26 rng: SmallRng::from_entropy(),
27 }
28 }
29}
30
31impl fmt::Debug for AppMeta {
32 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33 write!(
34 f,
35 "AppMeta {{ command_aliases: {:?}, demographics: {:?}, repository: {:?} }}",
36 self.command_aliases, self.demographics, self.repository,
37 )
38 }
39}
40
41#[cfg(test)]
42mod test {
43 use crate::test_utils as test;
44 use crate::world::Demographics;
45 use std::collections::HashMap;
46
47 #[test]
48 fn debug_test() {
49 let mut app_meta = test::app_meta();
50 app_meta.demographics = Demographics::new(HashMap::new());
51
52 assert_eq!(
53 "AppMeta { command_aliases: {}, demographics: Demographics { groups: GroupMapWrapper({}) }, repository: Repository { data_store_enabled: false, recent: [] } }",
54 format!("{:?}", app_meta),
55 );
56 }
57}