[][src]Attribute Macro iredismodule_macros::rwrap

#[rwrap]

Wrap of all kind of ffi fn and callback.

The first attr value is a kind, it's point out what kind of function to be wrapped.

free - wrap a free callback

#[rwrap("free")]
fn helloblock_free(ctx: &mut Context, data: Box<String>) { }

The code above will be expanded below

extern "C" fn helloblock_free_c(
    ctx: *mut iredismodule::raw::RedisModuleCtx,
    data: *mut std::os::raw::c_void,
) {
    use iredismodule::FromPtr;
    let mut context = iredismodule::context::Context::from_ptr(ctx);
    let data = data as *mut String;
    let data = unsafe { Box::from_raw(data) };
    helloblock_free(&mut context, data);
}
fn helloblock_free(ctx: &mut Context, data: Box<String>) {}

cmd - wrap a call callback

#[rwrap("call")]
fn helloblock_reply(ctx: &mut Context, _: Vec<RStr>) -> RResult {}

The code above will be expanded below

extern "C" fn helloblock_reply_c(
    ctx: *mut iredismodule::raw::RedisModuleCtx,
    argv: *mut *mut iredismodule::raw::RedisModuleString,
    argc: std::os::raw::c_int,
) -> std::os::raw::c_int {
    let args = iredismodule::parse_args(argv, argc);
    let mut context = iredismodule::context::Context::from_ptr(ctx);
    let result = helloblock_reply(&mut context, args);
    if result.is_err() {
        return iredismodule::raw::REDISMODULE_ERR as std::os::raw::c_int;
    }
    context.reply(result);
    return iredismodule::raw::REDISMODULE_OK as std::os::raw::c_int;
}
fn helloblock_reply(ctx: &mut Context, _: Vec<RStr>) -> RResult {