@@ -12,12 +12,12 @@ use crate::{RedisError, RedisResult, RedisString, RedisValue};
1212mod timer;
1313
1414#[ cfg( feature = "experimental-api" ) ]
15- pub ( crate ) mod thread_safe;
15+ pub mod thread_safe;
1616
1717#[ cfg( feature = "experimental-api" ) ]
18- pub ( crate ) mod blocked;
18+ pub mod blocked;
1919
20- pub ( crate ) mod info;
20+ pub mod info;
2121
2222/// `Context` is a structure that's designed to give us a high-level interface to
2323/// the Redis module API by abstracting away the raw C FFI calls.
@@ -26,11 +26,12 @@ pub struct Context {
2626}
2727
2828impl Context {
29- pub fn new ( ctx : * mut raw:: RedisModuleCtx ) -> Self {
29+ pub const fn new ( ctx : * mut raw:: RedisModuleCtx ) -> Self {
3030 Self { ctx }
3131 }
3232
33- pub fn dummy ( ) -> Self {
33+ #[ must_use]
34+ pub const fn dummy ( ) -> Self {
3435 Self {
3536 ctx : ptr:: null_mut ( ) ,
3637 }
@@ -68,6 +69,7 @@ impl Context {
6869 /// # Panics
6970 ///
7071 /// Will panic if `RedisModule_IsKeysPositionRequest` is missing in redismodule.h
72+ #[ must_use]
7173 pub fn is_keys_position_request ( & self ) -> bool {
7274 // We want this to be available in tests where we don't have an actual Redis to call
7375 if cfg ! ( feature = "test" ) {
@@ -127,7 +129,7 @@ impl Context {
127129 for i in 0 ..length {
128130 vec. push ( Self :: parse_call_reply ( raw:: call_reply_array_element (
129131 reply, i,
130- ) ) ?)
132+ ) ) ?) ;
131133 }
132134 Ok ( RedisValue :: Array ( vec) )
133135 }
@@ -137,6 +139,7 @@ impl Context {
137139 }
138140 }
139141
142+ #[ must_use]
140143 pub fn str_as_legal_resp_string ( s : & str ) -> CString {
141144 CString :: new (
142145 s. chars ( )
@@ -149,11 +152,13 @@ impl Context {
149152 . unwrap ( )
150153 }
151154
155+ #[ allow( clippy:: must_use_candidate) ]
152156 pub fn reply_simple_string ( & self , s : & str ) -> raw:: Status {
153157 let msg = Self :: str_as_legal_resp_string ( s) ;
154158 unsafe { raw:: RedisModule_ReplyWithSimpleString . unwrap ( ) ( self . ctx , msg. as_ptr ( ) ) . into ( ) }
155159 }
156160
161+ #[ allow( clippy:: must_use_candidate) ]
157162 pub fn reply_error_string ( & self , s : & str ) -> raw:: Status {
158163 let msg = Self :: str_as_legal_resp_string ( s) ;
159164 unsafe { raw:: RedisModule_ReplyWithError . unwrap ( ) ( self . ctx , msg. as_ptr ( ) ) . into ( ) }
@@ -162,6 +167,7 @@ impl Context {
162167 /// # Panics
163168 ///
164169 /// Will panic if methods used are missing in redismodule.h
170+ #[ allow( clippy:: must_use_candidate) ]
165171 pub fn reply ( & self , r : RedisResult ) -> raw:: Status {
166172 match r {
167173 Ok ( RedisValue :: Integer ( v) ) => unsafe {
@@ -185,7 +191,7 @@ impl Context {
185191 Ok ( RedisValue :: BulkString ( s) ) => unsafe {
186192 raw:: RedisModule_ReplyWithStringBuffer . unwrap ( ) (
187193 self . ctx ,
188- s. as_ptr ( ) as * const c_char ,
194+ s. as_ptr ( ) . cast :: < c_char > ( ) ,
189195 s. len ( ) as usize ,
190196 )
191197 . into ( )
@@ -198,7 +204,7 @@ impl Context {
198204 Ok ( RedisValue :: StringBuffer ( s) ) => unsafe {
199205 raw:: RedisModule_ReplyWithStringBuffer . unwrap ( ) (
200206 self . ctx ,
201- s. as_ptr ( ) as * const c_char ,
207+ s. as_ptr ( ) . cast :: < c_char > ( ) ,
202208 s. len ( ) as usize ,
203209 )
204210 . into ( )
@@ -243,10 +249,12 @@ impl Context {
243249 }
244250 }
245251
252+ #[ must_use]
246253 pub fn open_key ( & self , key : & RedisString ) -> RedisKey {
247254 RedisKey :: open ( self . ctx , key)
248255 }
249256
257+ #[ must_use]
250258 pub fn open_key_writable ( & self , key : & RedisString ) -> RedisKeyWritable {
251259 RedisKeyWritable :: open ( self . ctx , key)
252260 }
@@ -255,11 +263,13 @@ impl Context {
255263 raw:: replicate_verbatim ( self . ctx ) ;
256264 }
257265
266+ #[ must_use]
258267 pub fn create_string ( & self , s : & str ) -> RedisString {
259268 RedisString :: create ( self . ctx , s)
260269 }
261270
262- pub fn get_raw ( & self ) -> * mut raw:: RedisModuleCtx {
271+ #[ must_use]
272+ pub const fn get_raw ( & self ) -> * mut raw:: RedisModuleCtx {
263273 self . ctx
264274 }
265275
@@ -274,6 +284,7 @@ impl Context {
274284 }
275285
276286 #[ cfg( feature = "experimental-api" ) ]
287+ #[ allow( clippy:: must_use_candidate) ]
277288 pub fn notify_keyspace_event (
278289 & self ,
279290 event_type : raw:: NotifyEvent ,
@@ -283,7 +294,7 @@ impl Context {
283294 unsafe { raw:: notify_keyspace_event ( self . ctx , event_type, event, keyname) }
284295 }
285296
286- /// Returns the redis version either by calling RedisModule_GetServerVersion API,
297+ /// Returns the redis version either by calling `` RedisModule_GetServerVersion`` API,
287298 /// Or if it is not available, by calling "info server" API and parsing the reply
288299 pub fn get_redis_version ( & self ) -> Result < Version , RedisError > {
289300 self . get_redis_version_internal ( false )
@@ -332,18 +343,21 @@ pub struct InfoContext {
332343}
333344
334345impl InfoContext {
335- pub fn new ( ctx : * mut raw:: RedisModuleInfoCtx ) -> Self {
346+ pub const fn new ( ctx : * mut raw:: RedisModuleInfoCtx ) -> Self {
336347 Self { ctx }
337348 }
338349
350+ #[ allow( clippy:: must_use_candidate) ]
339351 pub fn add_info_section ( & self , name : Option < & str > ) -> Status {
340352 add_info_section ( self . ctx , name)
341353 }
342354
355+ #[ allow( clippy:: must_use_candidate) ]
343356 pub fn add_info_field_str ( & self , name : & str , content : & str ) -> Status {
344357 add_info_field_str ( self . ctx , name, content)
345358 }
346359
360+ #[ allow( clippy:: must_use_candidate) ]
347361 pub fn add_info_field_long_long ( & self , name : & str , value : c_longlong ) -> Status {
348362 add_info_field_long_long ( self . ctx , name, value)
349363 }
0 commit comments