1 | use proc_macro::{Ident, Span, TokenStream}; |
2 | |
3 | use super::modifier; |
4 | use crate::to_tokens::ToTokenStream; |
5 | |
6 | macro_rules! declare_component { |
7 | ($($name:ident)*) => { |
8 | pub(crate) enum Component {$( |
9 | $name(modifier::$name), |
10 | )*} |
11 | |
12 | impl ToTokenStream for Component { |
13 | fn append_to(self, ts: &mut TokenStream) { |
14 | let mut mts = TokenStream::new(); |
15 | |
16 | let component = match self {$( |
17 | Self::$name(modifier) => { |
18 | modifier.append_to(&mut mts); |
19 | stringify!($name) |
20 | } |
21 | )*}; |
22 | let component = Ident::new(component, Span::mixed_site()); |
23 | |
24 | quote_append! { ts |
25 | ::time::format_description::Component::#(component)(#S(mts)) |
26 | } |
27 | } |
28 | } |
29 | }; |
30 | } |
31 | |
32 | declare_component! { |
33 | Day |
34 | Month |
35 | Ordinal |
36 | Weekday |
37 | WeekNumber |
38 | Year |
39 | Hour |
40 | Minute |
41 | Period |
42 | Second |
43 | Subsecond |
44 | OffsetHour |
45 | OffsetMinute |
46 | OffsetSecond |
47 | Ignore |
48 | UnixTimestamp |
49 | End |
50 | } |
51 | |