config_docs/
config_docs.rs1pub trait ConfigDocs {
3 fn config_docs() -> &'static [(&'static str, &'static str)];
5}
6
7macro_rules! default_impl_for_types {
8 ($($t:ty),*) => {
9 $(
10 impl ConfigDocs for $t {
11 fn config_docs() -> &'static [(&'static str, &'static str)] {
12 &[]
13 }
14 }
15 )*
16 };
17}
18
19default_impl_for_types!(
21 i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize, f32, f64, String, &str
22);
23
24#[cfg(test)]
25mod test {
26 use super::*;
27 use config_docs_macros::ConfigDocs;
28
29 #[test]
30 fn it_parses_structs() {
31 #[allow(unused)]
32 #[derive(ConfigDocs)]
33 struct ThemeConfig {
34 fg: String,
39 bg: String,
44 }
45
46 assert_eq!(
47 ThemeConfig::config_docs(),
48 &[
49 ("fg", "Foreground color used in the text as a hex color"),
50 ("bg", "Background color used in the text as a hex color"),
51 ]
52 )
53 }
54
55 #[test]
56 fn it_parses_nested_structs() {
57 #[derive(ConfigDocs)]
58 #[allow(unused)]
59 struct Config {
60 pub theme: ThemeConfig,
62 pub keybinds: KeybindsConfig,
64 }
65 #[derive(ConfigDocs)]
66 #[allow(unused)]
67 struct ThemeConfig {
68 fg: String,
73 bg: String,
78 }
79 #[derive(ConfigDocs)]
80 #[allow(unused)]
81 struct KeybindsConfig {
82 help: String,
84 quit: String,
86 }
87
88 assert_eq!(
89 Config::config_docs(),
90 &[
91 ("theme", "Sets the colors used throughout the app"),
92 ("fg", "Foreground color used in the text as a hex color"),
93 ("bg", "Background color used in the text as a hex color"),
94 ("keybinds", "Sets the keybinds used throughout the app"),
95 ("help", "show help"),
96 ("quit", "quit app")
97 ]
98 )
99 }
100}