1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#![deny(missing_copy_implementations, missing_debug_implementations, missing_docs)]
use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};
use self::{
event::expand_event,
event_content::{
expand_basic_event_content, expand_ephemeral_room_event_content, expand_event_content,
expand_message_event_content, expand_room_event_content, expand_state_event_content,
},
event_enum::expand_event_enum,
event_parse::EventEnumInput,
};
mod event;
mod event_content;
mod event_enum;
mod event_parse;
#[proc_macro]
pub fn event_enum(input: TokenStream) -> TokenStream {
let event_enum_input = syn::parse_macro_input!(input as EventEnumInput);
expand_event_enum(event_enum_input).unwrap_or_else(|err| err.to_compile_error()).into()
}
#[proc_macro_derive(EventContent, attributes(ruma_event))]
pub fn derive_event_content(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
expand_event_content(&input, true).unwrap_or_else(|err| err.to_compile_error()).into()
}
#[proc_macro_derive(BasicEventContent, attributes(ruma_event))]
pub fn derive_basic_event_content(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
expand_basic_event_content(&input).unwrap_or_else(|err| err.to_compile_error()).into()
}
#[proc_macro_derive(RoomEventContent, attributes(ruma_event))]
pub fn derive_room_event_content(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
expand_room_event_content(&input).unwrap_or_else(|err| err.to_compile_error()).into()
}
#[proc_macro_derive(MessageEventContent, attributes(ruma_event))]
pub fn derive_message_event_content(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
expand_message_event_content(&input).unwrap_or_else(|err| err.to_compile_error()).into()
}
#[proc_macro_derive(StateEventContent, attributes(ruma_event))]
pub fn derive_state_event_content(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
expand_state_event_content(&input).unwrap_or_else(|err| err.to_compile_error()).into()
}
#[proc_macro_derive(EphemeralRoomEventContent, attributes(ruma_event))]
pub fn derive_ephemeral_room_event_content(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
expand_ephemeral_room_event_content(&input).unwrap_or_else(|err| err.to_compile_error()).into()
}
#[proc_macro_derive(Event, attributes(ruma_event))]
pub fn derive_state_event(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
expand_event(input).unwrap_or_else(|err| err.to_compile_error()).into()
}