Skip to content

Commit df56f94

Browse files
committed
add from_raw_parts creation method to RedisString
1 parent 350531c commit df56f94

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/redismodule.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ impl RedisString {
161161
Self { ctx, inner }
162162
}
163163

164+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
165+
pub fn from_raw_parts(ctx: Option<NonNull<raw::RedisModuleCtx>>, s: *const c_char, len: libc::size_t) -> Self {
166+
let ctx = ctx.map_or(std::ptr::null_mut(), |v| v.as_ptr());
167+
168+
let inner = unsafe {
169+
raw::RedisModule_CreateString.unwrap()(ctx, s, len)
170+
};
171+
172+
Self { ctx, inner }
173+
}
174+
164175
#[allow(clippy::not_unsafe_ptr_arg_deref)]
165176
pub fn create_from_slice(ctx: *mut raw::RedisModuleCtx, s: &[u8]) -> Self {
166177
let inner = unsafe {

0 commit comments

Comments
 (0)