Skip to content

Commit d6bb9cc

Browse files
committed
Revert the previous info argument of redis_module! macro.
The argument was optional and it is reverted to avoid the breaking changes. The way the macro is handled according to the new changes. The wrapping function should be inlined.
1 parent 9cbc3ba commit d6bb9cc

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

redismodule-rs-macros/src/info_section.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@ use proc_macro2::Ident;
33
use quote::{quote, ToTokens};
44
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Fields};
55

6-
struct SupportedMaps;
7-
impl SupportedMaps {
6+
mod supported_maps {
87
/// A list of supported maps which can be converted to a dictionary for
98
/// the [`redis_module::InfoContext`].
109
const ALL: [&str; 2] = ["BTreeMap", "HashMap"];
1110

1211
/// Returns `true` if the `type_string` provided is a type of a map
1312
/// supported by the [`crate::InfoSection`].
14-
pub fn supports(type_string: &str) -> bool {
15-
Self::ALL
16-
.iter()
17-
.any(|m| type_string.contains(&m.to_lowercase()))
13+
pub fn is_supported(type_string: &str) -> bool {
14+
ALL.iter().any(|m| type_string.contains(&m.to_lowercase()))
1815
}
1916
}
2017

@@ -41,7 +38,7 @@ fn struct_info_section(struct_name: Ident, struct_data: DataStruct) -> TokenStre
4138
.named
4239
.into_iter()
4340
.map(|v| {
44-
let is_dictionary = SupportedMaps::supports(
41+
let is_dictionary = supported_maps::is_supported(
4542
&v.ty.clone().into_token_stream().to_string().to_lowercase(),
4643
);
4744
let name = v.ident.ok_or(

src/macros.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ macro_rules! redis_module {
9999
],
100100
$(init: $init_func:ident,)* $(,)*
101101
$(deinit: $deinit_func:ident,)* $(,)*
102+
$(info: $info_func:ident,)?
102103
commands: [
103104
$([
104105
$name:expr,
@@ -155,6 +156,15 @@ macro_rules! redis_module {
155156
#[global_allocator]
156157
static REDIS_MODULE_ALLOCATOR: $allocator_type = $allocator_init;
157158

159+
// The info handler, if specified.
160+
$(
161+
#[redis_module_macros::info_command_handler]
162+
#[inline]
163+
fn module_info(ctx: &InfoContext, for_crash_report: bool) -> RedisResult<()> {
164+
$info_func(ctx, for_crash_report)
165+
}
166+
)?
167+
158168
extern "C" fn __info_func(
159169
ctx: *mut $crate::raw::RedisModuleInfoCtx,
160170
for_crash_report: i32,

0 commit comments

Comments
 (0)