Skip to main content

qimen_core/
symbols.rs

1//! Typed symbols shared by the chart model and the rotating-plate algorithm.
2
3use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7macro_rules! symbols {
8    ($(#[$meta:meta])* $name:ident { $($(#[$variant_meta:meta])* $variant:ident => $label:literal),+ $(,)? }) => {
9        $(#[$meta])*
10        #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
11        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
12        #[serde(rename_all = "snake_case")]
13        pub enum $name {
14            $($(#[$variant_meta])* $variant),+
15        }
16
17        impl $name {
18            /// Returns the traditional Chinese label.
19            #[must_use]
20            pub const fn name(self) -> &'static str {
21                match self { $(Self::$variant => $label),+ }
22            }
23        }
24
25        impl fmt::Display for $name {
26            fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
27                formatter.write_str(self.name())
28            }
29        }
30    };
31}
32
33symbols! {
34    /// Yang or yin dun, determined by the current solar term.
35    Dun {
36        /// 阳遁, winter solstice through the start of summer solstice.
37        Yang => "阳遁",
38        /// 阴遁, summer solstice through the start of winter solstice.
39        Yin => "阴遁",
40    }
41}
42
43symbols! {
44    /// The five-day yuan determined from the day's 甲/己 head.
45    Yuan {
46        /// 上元: the head's branch is 子午卯酉.
47        Upper => "上元",
48        /// 中元: the head's branch is 寅申巳亥.
49        Middle => "中元",
50        /// 下元: the head's branch is 辰戌丑未.
51        Lower => "下元",
52    }
53}
54
55symbols! {
56    /// A supported chart construction method.
57    Method {
58        /// 时家拆补转盘: use the active solar term and five-day head independently.
59        ShiJiaChaiBuZhuanPan => "时家拆补转盘",
60    }
61}
62
63symbols! {
64    /// Palace directions on the Later Heaven / Luo Shu arrangement.
65    Direction {
66        /// North.
67        North => "北",
68        /// Southwest.
69        Southwest => "西南",
70        /// East.
71        East => "东",
72        /// Southeast.
73        Southeast => "东南",
74        /// Center.
75        Center => "中",
76        /// Northwest.
77        Northwest => "西北",
78        /// West.
79        West => "西",
80        /// Northeast.
81        Northeast => "东北",
82        /// South.
83        South => "南",
84    }
85}
86
87symbols! {
88    /// One of the eight Later Heaven trigrams.
89    Trigram {
90        /// 坎, palace one.
91        Kan => "坎",
92        /// 坤, palace two.
93        Kun => "坤",
94        /// 震, palace three.
95        Zhen => "震",
96        /// 巽, palace four.
97        Xun => "巽",
98        /// 乾, palace six.
99        Qian => "乾",
100        /// 兑, palace seven.
101        Dui => "兑",
102        /// 艮, palace eight.
103        Gen => "艮",
104        /// 离, palace nine.
105        Li => "离",
106    }
107}
108
109symbols! {
110    /// One of the five traditional elements.
111    Element {
112        /// 木.
113        Wood => "木",
114        /// 火.
115        Fire => "火",
116        /// 土.
117        Earth => "土",
118        /// 金.
119        Metal => "金",
120        /// 水.
121        Water => "水",
122    }
123}
124
125symbols! {
126    /// One of the nine stars; 天禽 is explicitly carried with 天芮.
127    Star {
128        /// 天蓬, home palace one.
129        TianPeng => "天蓬",
130        /// 天芮, home palace two.
131        TianRui => "天芮",
132        /// 天冲, home palace three.
133        TianChong => "天冲",
134        /// 天辅, home palace four.
135        TianFu => "天辅",
136        /// 天禽, home palace five and hosted with 天芮.
137        TianQin => "天禽",
138        /// 天心, home palace six.
139        TianXin => "天心",
140        /// 天柱, home palace seven.
141        TianZhu => "天柱",
142        /// 天任, home palace eight.
143        TianRen => "天任",
144        /// 天英, home palace nine.
145        TianYing => "天英",
146    }
147}
148
149symbols! {
150    /// One of the eight doors.
151    Door {
152        /// 休门, home palace one.
153        Xiu => "休门",
154        /// 死门, home palace two.
155        Si => "死门",
156        /// 伤门, home palace three.
157        Shang => "伤门",
158        /// 杜门, home palace four.
159        Du => "杜门",
160        /// 开门, home palace six.
161        Kai => "开门",
162        /// 惊门, home palace seven.
163        Jing => "惊门",
164        /// 生门, home palace eight.
165        Sheng => "生门",
166        /// 景门, home palace nine.
167        Scene => "景门",
168    }
169}
170
171symbols! {
172    /// One of the eight deities, starting from the duty star's current palace.
173    Deity {
174        /// 值符.
175        ZhiFu => "值符",
176        /// 螣蛇.
177        TengShe => "螣蛇",
178        /// 太阴.
179        TaiYin => "太阴",
180        /// 六合.
181        LiuHe => "六合",
182        /// 白虎.
183        BaiHu => "白虎",
184        /// 玄武.
185        XuanWu => "玄武",
186        /// 九地.
187        JiuDi => "九地",
188        /// 九天.
189        JiuTian => "九天",
190    }
191}