Skip to main content

kosher_rust/limudim/
units.rs

1/// A tractate of the Talmud (Bavli or Yerushalmi).
2#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
3#[cfg_attr(feature = "defmt", derive(defmt::Format))]
4#[allow(missing_docs)]
5pub enum Tractate {
6    Berachos,
7    Peah,
8    Demai,
9    Kilayim,
10    Sheviis,
11    Terumos,
12    Maasros,
13    MaaserSheni,
14    Chalah,
15    Orlah,
16    Bikurim,
17    Shabbos,
18    Eruvin,
19    Pesachim,
20    Shekalim,
21    Yoma,
22    Sukkah,
23    Beitzah,
24    RoshHashanah,
25    Taanis,
26    Megillah,
27    MoedKatan,
28    Chagigah,
29    Yevamos,
30    Kesubos,
31    Nedarim,
32    Nazir,
33    Sotah,
34    Gitin,
35    Kiddushin,
36    BavaKamma,
37    BavaMetzia,
38    BavaBasra,
39    Sanhedrin,
40    Makkos,
41    Shevuos,
42    Eduyos,
43    AvodahZarah,
44    Avos,
45    Horiyos,
46    Zevachim,
47    Menachos,
48    Chullin,
49    Bechoros,
50    Arachin,
51    Temurah,
52    Kerisos,
53    Meilah,
54    Tamid,
55    Midos,
56    Kinnim,
57    Keilim,
58    Ohalos,
59    Negaim,
60    Parah,
61    Taharos,
62    Mikvaos,
63    Niddah,
64    Machshirin,
65    Zavim,
66    TevulYom,
67    Yadayim,
68    Uktzin,
69}
70/// A list of all the tractates in Talmud Bavli.
71pub const TRACTATES: [Tractate; 63] = [
72    Tractate::Berachos,
73    Tractate::Peah,
74    Tractate::Demai,
75    Tractate::Kilayim,
76    Tractate::Sheviis,
77    Tractate::Terumos,
78    Tractate::Maasros,
79    Tractate::MaaserSheni,
80    Tractate::Chalah,
81    Tractate::Orlah,
82    Tractate::Bikurim,
83    Tractate::Shabbos,
84    Tractate::Eruvin,
85    Tractate::Pesachim,
86    Tractate::Shekalim,
87    Tractate::Yoma,
88    Tractate::Sukkah,
89    Tractate::Beitzah,
90    Tractate::RoshHashanah,
91    Tractate::Taanis,
92    Tractate::Megillah,
93    Tractate::MoedKatan,
94    Tractate::Chagigah,
95    Tractate::Yevamos,
96    Tractate::Kesubos,
97    Tractate::Nedarim,
98    Tractate::Nazir,
99    Tractate::Sotah,
100    Tractate::Gitin,
101    Tractate::Kiddushin,
102    Tractate::BavaKamma,
103    Tractate::BavaMetzia,
104    Tractate::BavaBasra,
105    Tractate::Sanhedrin,
106    Tractate::Makkos,
107    Tractate::Shevuos,
108    Tractate::Eduyos,
109    Tractate::AvodahZarah,
110    Tractate::Avos,
111    Tractate::Horiyos,
112    Tractate::Zevachim,
113    Tractate::Menachos,
114    Tractate::Chullin,
115    Tractate::Bechoros,
116    Tractate::Arachin,
117    Tractate::Temurah,
118    Tractate::Kerisos,
119    Tractate::Meilah,
120    Tractate::Tamid,
121    Tractate::Midos,
122    Tractate::Kinnim,
123    Tractate::Keilim,
124    Tractate::Ohalos,
125    Tractate::Negaim,
126    Tractate::Parah,
127    Tractate::Taharos,
128    Tractate::Mikvaos,
129    Tractate::Niddah,
130    Tractate::Machshirin,
131    Tractate::Zavim,
132    Tractate::TevulYom,
133    Tractate::Yadayim,
134    Tractate::Uktzin,
135];
136/// A list of all the tractates in Talmud Bavli.
137pub const BAVLI_TRACTATES: [Tractate; 40] = [
138    Tractate::Berachos,
139    Tractate::Shabbos,
140    Tractate::Eruvin,
141    Tractate::Pesachim,
142    Tractate::Shekalim,
143    Tractate::Yoma,
144    Tractate::Sukkah,
145    Tractate::Beitzah,
146    Tractate::RoshHashanah,
147    Tractate::Taanis,
148    Tractate::Megillah,
149    Tractate::MoedKatan,
150    Tractate::Chagigah,
151    Tractate::Yevamos,
152    Tractate::Kesubos,
153    Tractate::Nedarim,
154    Tractate::Nazir,
155    Tractate::Sotah,
156    Tractate::Gitin,
157    Tractate::Kiddushin,
158    Tractate::BavaKamma,
159    Tractate::BavaMetzia,
160    Tractate::BavaBasra,
161    Tractate::Sanhedrin,
162    Tractate::Makkos,
163    Tractate::Shevuos,
164    Tractate::AvodahZarah,
165    Tractate::Horiyos,
166    Tractate::Zevachim,
167    Tractate::Menachos,
168    Tractate::Chullin,
169    Tractate::Bechoros,
170    Tractate::Arachin,
171    Tractate::Temurah,
172    Tractate::Kerisos,
173    Tractate::Meilah,
174    Tractate::Kinnim,
175    Tractate::Tamid,
176    Tractate::Midos,
177    Tractate::Niddah,
178];
179
180/// A list of all the tractates in Talmud Yerushalmi.
181pub const YERUSHALMI_TRACTATES: [Tractate; 39] = [
182    Tractate::Berachos,
183    Tractate::Peah,
184    Tractate::Demai,
185    Tractate::Kilayim,
186    Tractate::Sheviis,
187    Tractate::Terumos,
188    Tractate::Maasros,
189    Tractate::MaaserSheni,
190    Tractate::Chalah,
191    Tractate::Orlah,
192    Tractate::Bikurim,
193    Tractate::Shabbos,
194    Tractate::Eruvin,
195    Tractate::Pesachim,
196    Tractate::Beitzah,
197    Tractate::RoshHashanah,
198    Tractate::Yoma,
199    Tractate::Sukkah,
200    Tractate::Taanis,
201    Tractate::Shekalim,
202    Tractate::Megillah,
203    Tractate::Chagigah,
204    Tractate::MoedKatan,
205    Tractate::Yevamos,
206    Tractate::Kesubos,
207    Tractate::Sotah,
208    Tractate::Nedarim,
209    Tractate::Nazir,
210    Tractate::Gitin,
211    Tractate::Kiddushin,
212    Tractate::BavaKamma,
213    Tractate::BavaMetzia,
214    Tractate::BavaBasra,
215    Tractate::Shevuos,
216    Tractate::Makkos,
217    Tractate::Sanhedrin,
218    Tractate::AvodahZarah,
219    Tractate::Horiyos,
220    Tractate::Niddah,
221];
222
223#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
224#[cfg_attr(feature = "defmt", derive(defmt::Format))]
225#[allow(missing_docs)]
226pub struct Daf {
227    pub tractate: Tractate,
228    /// The page number of the amud. Starts at 2 for Talmud Bavli and 1 for Talmud Yerushalmi.
229    pub page: u16,
230}
231#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
232#[cfg_attr(feature = "defmt", derive(defmt::Format))]
233#[allow(missing_docs)]
234pub enum Side {
235    Aleph,
236    Bet,
237}
238
239#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
240#[cfg_attr(feature = "defmt", derive(defmt::Format))]
241#[allow(missing_docs)]
242pub struct Amud {
243    pub tractate: Tractate,
244    /// The page number of the amud. Starts at 2 for Talmud Bavli and 1 for Talmud Yerushalmi.
245    pub page: u16,
246    pub side: Side,
247}
248impl Amud {
249    pub(crate) const fn new(tractate: Tractate, page: u16, side: Side) -> Self {
250        Self { tractate, page, side }
251    }
252
253    fn page_side_index(self) -> usize {
254        self.page as usize * 2
255            + match self.side {
256                Side::Aleph => 0,
257                Side::Bet => 1,
258            }
259    }
260
261    /// Number of amudim from `self` through `end`, inclusive.
262    ///
263    /// Returns `None` if the tractates differ or if this tractate starts after `end`.
264    /// e.g. Kiddushin 2a through 2b → `2`.
265    pub fn amudim_to(self, end: Self) -> Option<i32> {
266        if self.tractate != end.tractate {
267            return None;
268        }
269        let start = self.page_side_index();
270        let end_index = end.page_side_index();
271        if start > end_index {
272            return None;
273        }
274        Some((end_index - start + 1) as i32)
275    }
276
277    /// Amud at a 0-based offset from `self` (offset 0 returns `self`).
278    pub fn at_offset(self, offset: i32) -> Option<Self> {
279        if offset < 0 {
280            return None;
281        }
282        let index = self.page_side_index() + offset as usize;
283        Some(Self::new(
284            self.tractate,
285            (index / 2) as u16,
286            if index.is_multiple_of(2) {
287                Side::Aleph
288            } else {
289                Side::Bet
290            },
291        ))
292    }
293}
294
295#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
296#[cfg_attr(feature = "defmt", derive(defmt::Format))]
297#[allow(missing_docs)]
298pub struct Mishna {
299    pub tractate: Tractate,
300    pub chapter: usize,
301    pub mishna: u16,
302}