#[derive(InfoSection)]
Expand description
Implements a corresponding From
for this struct, to convert
objects of this struct to an information object to be sent to the
[redis_module::InfoContext
] as a reply.
Example:
ⓘ
#[derive(InfoSection)]
struct Info {
field_1: String,
field_2: u64,
dictionary_1: BTreeMap<String, String>,
}
This procedural macro only implements an easy way to convert objects
of this struct, it doesn’t automatically do anything. To actually
make use of this, we must return an object of this struct from the
corresponding handler (info
handler):
ⓘ
static mut INFO: Info = Info::new();
#[info_command_handler]
fn info_command_handler(
ctx: &InfoContext,
_for_crash_report: bool) -> RedisResult
{
ctx.build_one_section(INFO)
}
§Notes
- The name of the struct is taken “as is”, so if it starts with
a capital letter (written in the “Upper Camel Case”), like in this
example -
Info
, then it will be compiled into a string prefixed with the module name, ending up being"module_name_Info"
-named section. The fields of the struct are also prefixed with the module name, so thefield_1
will be prefixed withmodule_name_
as well. - In dictionaries, the type of dictionaries supported varies,
for now it is
std::collections::BTreeMap
andstd::collections::HashMap
. - In dictionaries, the value type can be anything that can be
converted into an object of type
[
redis_module::InfoContextBuilderFieldBottomLevelValue
], for example, astd::string::String
oru64
. Please, refer to [redis_module::InfoContextBuilderFieldBottomLevelValue
] for more information.