Skip to main content

rust_zmanim/complex_zmanim_calendar/
czc_macros.rs

1#[macro_export]
2macro_rules! zmanim_for_offset {
3    // Main entry point
4    ($offset_fn:expr, [$($fn_name:ident => $zman_type:ident, $doc:expr),* $(,)?]) => {
5        $(
6            zmanim_for_offset!(@method_custom $fn_name, $offset_fn, $zman_type, $doc);
7        )*
8    };
9
10    // shaah_zmanis_mga - separate variant due to different return type (TimeDelta)
11    (@method_custom $fn_name:ident, $offset_fn:expr, shaah_zmanis_mga, $doc:expr) => {
12        #[must_use]
13        #[doc = $doc]
14        pub fn $fn_name(&self) -> Option<TimeDelta> {
15            let offset = ($offset_fn)(self)?;
16            self.shaah_zmanis_mga(&offset)
17        }
18    };
19
20    // Generic variant for other zman types returning DateTime<Tz>
21    (@method_custom $fn_name:ident, $offset_fn:expr, $zman_type:ident, $doc:expr) => {
22        #[must_use]
23        #[doc = $doc]
24        pub fn $fn_name(&self) -> Option<DateTime<Tz>> {
25            let offset = ($offset_fn)(self)?;
26            self.$zman_type(&offset)
27        }
28    };
29}