@@ -317,6 +317,9 @@ impl TopicPartitionList {
317
317
318
318
/// Sets all partitions in the list to the specified offset.
319
319
pub fn set_all_offsets ( & mut self , offset : Offset ) -> Result < ( ) , KafkaError > {
320
+ if self . count ( ) == 0 {
321
+ return Ok ( ( ) ) ;
322
+ }
320
323
let slice = unsafe { slice:: from_raw_parts_mut ( self . ptr . elems , self . count ( ) ) } ;
321
324
for elem_ptr in slice {
322
325
let mut elem = TopicPartitionListElem :: from_ptr ( self , & mut * elem_ptr) ;
@@ -327,8 +330,11 @@ impl TopicPartitionList {
327
330
328
331
/// Returns all the elements of the list.
329
332
pub fn elements ( & self ) -> Vec < TopicPartitionListElem < ' _ > > {
333
+ let mut vec = Vec :: with_capacity ( self . count ( ) ) ;
334
+ if self . count ( ) == 0 {
335
+ return vec;
336
+ }
330
337
let slice = unsafe { slice:: from_raw_parts_mut ( self . ptr . elems , self . count ( ) ) } ;
331
- let mut vec = Vec :: with_capacity ( slice. len ( ) ) ;
332
338
for elem_ptr in slice {
333
339
vec. push ( TopicPartitionListElem :: from_ptr ( self , & mut * elem_ptr) ) ;
334
340
}
@@ -337,8 +343,11 @@ impl TopicPartitionList {
337
343
338
344
/// Returns all the elements of the list that belong to the specified topic.
339
345
pub fn elements_for_topic < ' a > ( & ' a self , topic : & str ) -> Vec < TopicPartitionListElem < ' a > > {
346
+ let mut vec = Vec :: with_capacity ( self . count ( ) ) ;
347
+ if self . count ( ) == 0 {
348
+ return vec;
349
+ }
340
350
let slice = unsafe { slice:: from_raw_parts_mut ( self . ptr . elems , self . count ( ) ) } ;
341
- let mut vec = Vec :: with_capacity ( slice. len ( ) ) ;
342
351
for elem_ptr in slice {
343
352
let tp = TopicPartitionListElem :: from_ptr ( self , & mut * elem_ptr) ;
344
353
if tp. topic ( ) == topic {
0 commit comments