@@ -84,6 +84,15 @@ pub fn command(attr: TokenStream, item: TokenStream) -> TokenStream {
8484 command:: redis_command ( attr, item)
8585}
8686
87+ /// Proc macro which is set on a function that need to be called whenever the server role changes.
88+ /// The function must accept a [Context] and [ServerRole].
89+ ///
90+ /// Example:
91+ ///
92+ /// ```rust,no_run,ignore
93+ /// #[role_changed_event_handler]
94+ /// fn role_changed_event_handler(ctx: &Context, values: ServerRole) { ... }
95+ /// ```
8796#[ proc_macro_attribute]
8897pub fn role_changed_event_handler ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
8998 let ast: ItemFn = match syn:: parse ( item) {
@@ -97,6 +106,15 @@ pub fn role_changed_event_handler(_attr: TokenStream, item: TokenStream) -> Toke
97106 gen. into ( )
98107}
99108
109+ /// Proc macro which is set on a function that need to be called whenever a loading event happened.
110+ /// The function must accept a [Context] and [LoadingSubevent].
111+ ///
112+ /// Example:
113+ ///
114+ /// ```rust,no_run,ignore
115+ /// #[loading_event_handler]
116+ /// fn loading_event_handler(ctx: &Context, values: LoadingSubevent) { ... }
117+ /// ```
100118#[ proc_macro_attribute]
101119pub fn loading_event_handler ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
102120 let ast: ItemFn = match syn:: parse ( item) {
@@ -110,6 +128,15 @@ pub fn loading_event_handler(_attr: TokenStream, item: TokenStream) -> TokenStre
110128 gen. into ( )
111129}
112130
131+ /// Proc macro which is set on a function that need to be called whenever a flush event happened.
132+ /// The function must accept a [Context] and [FlushSubevent].
133+ ///
134+ /// Example:
135+ ///
136+ /// ```rust,no_run,ignore
137+ /// #[flush_event_handler]
138+ /// fn flush_event_handler(ctx: &Context, values: FlushSubevent) { ... }
139+ /// ```
113140#[ proc_macro_attribute]
114141pub fn flush_event_handler ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
115142 let ast: ItemFn = match syn:: parse ( item) {
@@ -123,6 +150,15 @@ pub fn flush_event_handler(_attr: TokenStream, item: TokenStream) -> TokenStream
123150 gen. into ( )
124151}
125152
153+ /// Proc macro which is set on a function that need to be called whenever a module is loaded or unloaded on the server.
154+ /// The function must accept a [Context] and [ModuleChangeSubevent].
155+ ///
156+ /// Example:
157+ ///
158+ /// ```rust,no_run,ignore
159+ /// #[module_changed_event_handler]
160+ /// fn module_changed_event_handler(ctx: &Context, values: ModuleChangeSubevent) { ... }
161+ /// ```
126162#[ proc_macro_attribute]
127163pub fn module_changed_event_handler ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
128164 let ast: ItemFn = match syn:: parse ( item) {
@@ -136,6 +172,29 @@ pub fn module_changed_event_handler(_attr: TokenStream, item: TokenStream) -> To
136172 gen. into ( )
137173}
138174
175+ /// Proc macro which is set on a function that need to be called whenever a configuration change
176+ /// event is happening. The function must accept a [Context] and [&[&str]] that contains the names
177+ /// of the configiration values that was changed.
178+ ///
179+ /// Example:
180+ ///
181+ /// ```rust,no_run,ignore
182+ /// #[config_changed_event_handler]
183+ /// fn configuration_changed_event_handler(ctx: &Context, values: &[&str]) { ... }
184+ /// ```
185+ #[ proc_macro_attribute]
186+ pub fn config_changed_event_handler ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
187+ let ast: ItemFn = match syn:: parse ( item) {
188+ Ok ( res) => res,
189+ Err ( e) => return e. to_compile_error ( ) . into ( ) ,
190+ } ;
191+ let gen = quote ! {
192+ #[ linkme:: distributed_slice( redis_module:: server_events:: CONFIG_CHANGED_SERVER_EVENTS_LIST ) ]
193+ #ast
194+ } ;
195+ gen. into ( )
196+ }
197+
139198/// The macro auto generate a [From] implementation that can convert the struct into [RedisValue].
140199///
141200/// Example:
0 commit comments