@@ -324,13 +324,14 @@ pub fn create_pool(
324324///
325325/// Provides predefined size classes for efficient multi-size pooling.
326326/// Allocations are rounded up to the smallest bucket that fits.
327- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
327+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , Default ) ]
328328pub enum SizeBucket {
329329 /// Tiny buffers (256 bytes) - metadata, small messages.
330330 Tiny ,
331331 /// Small buffers (1 KB) - typical message payloads.
332332 Small ,
333333 /// Medium buffers (4 KB) - page-sized allocations.
334+ #[ default]
334335 Medium ,
335336 /// Large buffers (16 KB) - batch operations.
336337 Large ,
@@ -399,12 +400,6 @@ impl SizeBucket {
399400 }
400401}
401402
402- impl Default for SizeBucket {
403- fn default ( ) -> Self {
404- Self :: Medium
405- }
406- }
407-
408403impl std:: fmt:: Display for SizeBucket {
409404 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
410405 match self {
@@ -442,7 +437,11 @@ impl StratifiedPoolStats {
442437
443438 /// Get hit rate for a specific bucket.
444439 pub fn bucket_hit_rate ( & self , bucket : SizeBucket ) -> f64 {
445- let allocs = self . allocations_per_bucket . get ( & bucket) . copied ( ) . unwrap_or ( 0 ) ;
440+ let allocs = self
441+ . allocations_per_bucket
442+ . get ( & bucket)
443+ . copied ( )
444+ . unwrap_or ( 0 ) ;
446445 let hits = self . hits_per_bucket . get ( & bucket) . copied ( ) . unwrap_or ( 0 ) ;
447446 if allocs == 0 {
448447 0.0
@@ -495,7 +494,10 @@ impl StratifiedMemoryPool {
495494
496495 for bucket in SizeBucket :: ALL {
497496 let pool_name = format ! ( "{}_{}" , name, bucket) ;
498- buckets. insert ( bucket, MemoryPool :: new ( pool_name, bucket. size ( ) , max_buffers_per_bucket) ) ;
497+ buckets. insert (
498+ bucket,
499+ MemoryPool :: new ( pool_name, bucket. size ( ) , max_buffers_per_bucket) ,
500+ ) ;
499501 }
500502
501503 Self {
@@ -552,7 +554,10 @@ impl StratifiedMemoryPool {
552554
553555 /// Get current size of a specific bucket pool.
554556 pub fn bucket_size ( & self , bucket : SizeBucket ) -> usize {
555- self . buckets . get ( & bucket) . map ( |p| p. current_size ( ) ) . unwrap_or ( 0 )
557+ self . buckets
558+ . get ( & bucket)
559+ . map ( |p| p. current_size ( ) )
560+ . unwrap_or ( 0 )
556561 }
557562
558563 /// Get total buffers currently pooled across all buckets.
@@ -662,7 +667,10 @@ pub fn create_stratified_pool_with_capacity(
662667 name : impl Into < String > ,
663668 max_buffers_per_bucket : usize ,
664669) -> SharedStratifiedPool {
665- Arc :: new ( StratifiedMemoryPool :: with_capacity ( name, max_buffers_per_bucket) )
670+ Arc :: new ( StratifiedMemoryPool :: with_capacity (
671+ name,
672+ max_buffers_per_bucket,
673+ ) )
666674}
667675
668676// ============================================================================
@@ -698,7 +706,11 @@ impl std::fmt::Debug for PressureReaction {
698706 match self {
699707 Self :: None => write ! ( f, "PressureReaction::None" ) ,
700708 Self :: Shrink { target_utilization } => {
701- write ! ( f, "PressureReaction::Shrink {{ target_utilization: {} }}" , target_utilization)
709+ write ! (
710+ f,
711+ "PressureReaction::Shrink {{ target_utilization: {} }}" ,
712+ target_utilization
713+ )
702714 }
703715 Self :: Callback ( _) => write ! ( f, "PressureReaction::Callback(<fn>)" ) ,
704716 }
@@ -1006,9 +1018,9 @@ mod tests {
10061018 let pool = StratifiedMemoryPool :: new ( "test" ) ;
10071019
10081020 // Allocate different sizes
1009- let buf1 = pool. allocate ( 100 ) ; // Tiny
1010- let buf2 = pool. allocate ( 500 ) ; // Small
1011- let buf3 = pool. allocate ( 2000 ) ; // Medium
1021+ let buf1 = pool. allocate ( 100 ) ; // Tiny
1022+ let buf2 = pool. allocate ( 500 ) ; // Small
1023+ let buf3 = pool. allocate ( 2000 ) ; // Medium
10121024
10131025 assert_eq ! ( buf1. bucket( ) , SizeBucket :: Tiny ) ;
10141026 assert_eq ! ( buf2. bucket( ) , SizeBucket :: Small ) ;
@@ -1046,14 +1058,20 @@ mod tests {
10461058 let pool = StratifiedMemoryPool :: new ( "test" ) ;
10471059
10481060 // Allocate from different buckets
1049- let _buf1 = pool. allocate ( 100 ) ; // Tiny
1050- let _buf2 = pool. allocate ( 500 ) ; // Small
1051- let _buf3 = pool. allocate ( 100 ) ; // Tiny again
1061+ let _buf1 = pool. allocate ( 100 ) ; // Tiny
1062+ let _buf2 = pool. allocate ( 500 ) ; // Small
1063+ let _buf3 = pool. allocate ( 100 ) ; // Tiny again
10521064
10531065 let stats = pool. stats ( ) ;
10541066 assert_eq ! ( stats. total_allocations, 3 ) ;
1055- assert_eq ! ( stats. allocations_per_bucket. get( & SizeBucket :: Tiny ) , Some ( & 2 ) ) ;
1056- assert_eq ! ( stats. allocations_per_bucket. get( & SizeBucket :: Small ) , Some ( & 1 ) ) ;
1067+ assert_eq ! (
1068+ stats. allocations_per_bucket. get( & SizeBucket :: Tiny ) ,
1069+ Some ( & 2 )
1070+ ) ;
1071+ assert_eq ! (
1072+ stats. allocations_per_bucket. get( & SizeBucket :: Small ) ,
1073+ Some ( & 1 )
1074+ ) ;
10571075 }
10581076
10591077 #[ test]
@@ -1173,7 +1191,9 @@ mod tests {
11731191 let none = PressureReaction :: None ;
11741192 assert ! ( format!( "{:?}" , none) . contains( "None" ) ) ;
11751193
1176- let shrink = PressureReaction :: Shrink { target_utilization : 0.5 } ;
1194+ let shrink = PressureReaction :: Shrink {
1195+ target_utilization : 0.5 ,
1196+ } ;
11771197 assert ! ( format!( "{:?}" , shrink) . contains( "0.5" ) ) ;
11781198
11791199 let callback = PressureReaction :: Callback ( Box :: new ( |_| { } ) ) ;
0 commit comments