@@ -45,7 +45,7 @@ use std::ffi::{CStr, CString};
45
45
use std:: marker:: PhantomData ;
46
46
use std:: mem;
47
47
use std:: os:: raw:: c_void;
48
- use std:: ptr:: { self , null_mut } ;
48
+ use std:: ptr;
49
49
use std:: slice;
50
50
use std:: str;
51
51
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
@@ -232,8 +232,14 @@ unsafe extern "C" fn partitioner_cb<Part: Partitioner, C: ProducerContext<Part>>
232
232
Some ( slice:: from_raw_parts ( keydata as * const u8 , keylen) )
233
233
} ;
234
234
235
- let producer_context: & mut Part = & mut * ( rkt_opaque as * mut Part ) ;
236
- producer_context. partition ( topic_name, key, partition_cnt, is_partition_available)
235
+ let producer_context = & mut * ( rkt_opaque as * mut C ) ;
236
+
237
+ match producer_context. get_custom_partitioner ( ) {
238
+ None => panic ! ( "custom partitioner is not set" ) ,
239
+ Some ( partitioner) => {
240
+ partitioner. partition ( topic_name, key, partition_cnt, is_partition_available)
241
+ }
242
+ }
237
243
}
238
244
239
245
impl FromClientConfig for BaseProducer < DefaultProducerContext > {
@@ -260,15 +266,15 @@ where
260
266
let native_config = config. create_native_config ( ) ?;
261
267
let context = Arc :: new ( context) ;
262
268
263
- let partitioner = match context. get_custom_partitioner ( ) {
264
- None => null_mut ( ) ,
265
- Some ( partitioner) => partitioner as * const Part as * mut c_void ,
266
- } ;
267
-
268
- if !partitioner. is_null ( ) {
269
+ if let Some ( _) = context. get_custom_partitioner ( ) {
269
270
let default_topic_config =
270
271
unsafe { rdsys:: rd_kafka_conf_get_default_topic_conf ( native_config. ptr ( ) ) } ;
271
- unsafe { rdsys:: rd_kafka_topic_conf_set_opaque ( default_topic_config, partitioner) } ;
272
+ unsafe {
273
+ rdsys:: rd_kafka_topic_conf_set_opaque (
274
+ default_topic_config,
275
+ Arc :: as_ptr ( & context) as * const Part as * mut c_void ,
276
+ )
277
+ } ;
272
278
unsafe {
273
279
rdsys:: rd_kafka_topic_conf_set_partitioner_cb (
274
280
default_topic_config,
0 commit comments