@@ -150,7 +150,7 @@ impl<'de> Deserialize<'de> for ChannelState {
150150pub ( crate ) struct ChannelStats {
151151 pub ( crate ) id : u64 ,
152152 pub ( crate ) source : & ' static str ,
153- pub ( crate ) label : Option < & ' static str > ,
153+ pub ( crate ) label : Option < String > ,
154154 pub ( crate ) channel_type : ChannelType ,
155155 pub ( crate ) state : ChannelState ,
156156 pub ( crate ) sent_count : u64 ,
@@ -203,7 +203,7 @@ pub struct SerializableChannelStats {
203203
204204impl From < & ChannelStats > for SerializableChannelStats {
205205 fn from ( stats : & ChannelStats ) -> Self {
206- let label = resolve_label ( stats. source , stats. label , stats. iter ) ;
206+ let label = resolve_label ( stats. source , stats. label . as_deref ( ) , stats. iter ) ;
207207
208208 Self {
209209 id : stats. id ,
@@ -227,7 +227,7 @@ impl ChannelStats {
227227 fn new (
228228 id : u64 ,
229229 source : & ' static str ,
230- label : Option < & ' static str > ,
230+ label : Option < String > ,
231231 channel_type : ChannelType ,
232232 type_name : & ' static str ,
233233 type_size : usize ,
@@ -275,7 +275,7 @@ pub(crate) enum StatsEvent {
275275 Created {
276276 id : u64 ,
277277 source : & ' static str ,
278- display_label : Option < & ' static str > ,
278+ display_label : Option < String > ,
279279 channel_type : ChannelType ,
280280 type_name : & ' static str ,
281281 type_size : usize ,
@@ -424,7 +424,7 @@ fn init_stats_state() -> &'static StatsState {
424424 } )
425425}
426426
427- fn resolve_label ( id : & ' static str , provided : Option < & ' static str > , iter : u32 ) -> String {
427+ fn resolve_label ( id : & ' static str , provided : Option < & str > , iter : u32 ) -> String {
428428 let base_label = if let Some ( l) = provided {
429429 l. to_string ( )
430430 } else if let Some ( pos) = id. rfind ( ':' ) {
@@ -486,7 +486,7 @@ pub trait Instrument {
486486 fn instrument (
487487 self ,
488488 source : & ' static str ,
489- label : Option < & ' static str > ,
489+ label : Option < String > ,
490490 capacity : Option < usize > ,
491491 ) -> Self :: Output ;
492492}
@@ -500,7 +500,7 @@ pub trait InstrumentLog {
500500 fn instrument_log (
501501 self ,
502502 source : & ' static str ,
503- label : Option < & ' static str > ,
503+ label : Option < String > ,
504504 capacity : Option < usize > ,
505505 ) -> Self :: Output ;
506506}
@@ -593,9 +593,9 @@ macro_rules! instrument {
593593 $crate:: Instrument :: instrument( $expr, CHANNEL_ID , None , None )
594594 } } ;
595595
596- ( $expr: expr, label = $label: literal ) => { {
596+ ( $expr: expr, label = $label: expr ) => { {
597597 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
598- $crate:: Instrument :: instrument( $expr, CHANNEL_ID , Some ( $label) , None )
598+ $crate:: Instrument :: instrument( $expr, CHANNEL_ID , Some ( $label. to_string ( ) ) , None )
599599 } } ;
600600
601601 ( $expr: expr, capacity = $capacity: expr) => { {
@@ -604,16 +604,16 @@ macro_rules! instrument {
604604 $crate:: Instrument :: instrument( $expr, CHANNEL_ID , None , Some ( $capacity) )
605605 } } ;
606606
607- ( $expr: expr, label = $label: literal , capacity = $capacity: expr) => { {
607+ ( $expr: expr, label = $label: expr , capacity = $capacity: expr) => { {
608608 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
609609 const _: usize = $capacity;
610- $crate:: Instrument :: instrument( $expr, CHANNEL_ID , Some ( $label) , Some ( $capacity) )
610+ $crate:: Instrument :: instrument( $expr, CHANNEL_ID , Some ( $label. to_string ( ) ) , Some ( $capacity) )
611611 } } ;
612612
613- ( $expr: expr, capacity = $capacity: expr, label = $label: literal ) => { {
613+ ( $expr: expr, capacity = $capacity: expr, label = $label: expr ) => { {
614614 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
615615 const _: usize = $capacity;
616- $crate:: Instrument :: instrument( $expr, CHANNEL_ID , Some ( $label) , Some ( $capacity) )
616+ $crate:: Instrument :: instrument( $expr, CHANNEL_ID , Some ( $label. to_string ( ) ) , Some ( $capacity) )
617617 } } ;
618618
619619 // Variants with log = true
@@ -622,14 +622,14 @@ macro_rules! instrument {
622622 $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , None , None )
623623 } } ;
624624
625- ( $expr: expr, label = $label: literal , log = true ) => { {
625+ ( $expr: expr, label = $label: expr , log = true ) => { {
626626 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
627- $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label) , None )
627+ $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label. to_string ( ) ) , None )
628628 } } ;
629629
630- ( $expr: expr, log = true , label = $label: literal ) => { {
630+ ( $expr: expr, log = true , label = $label: expr ) => { {
631631 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
632- $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label) , None )
632+ $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label. to_string ( ) ) , None )
633633 } } ;
634634
635635 ( $expr: expr, capacity = $capacity: expr, log = true ) => { {
@@ -644,40 +644,70 @@ macro_rules! instrument {
644644 $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , None , Some ( $capacity) )
645645 } } ;
646646
647- ( $expr: expr, label = $label: literal , capacity = $capacity: expr, log = true ) => { {
647+ ( $expr: expr, label = $label: expr , capacity = $capacity: expr, log = true ) => { {
648648 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
649649 const _: usize = $capacity;
650- $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label) , Some ( $capacity) )
650+ $crate:: InstrumentLog :: instrument_log(
651+ $expr,
652+ CHANNEL_ID ,
653+ Some ( $label. to_string( ) ) ,
654+ Some ( $capacity) ,
655+ )
651656 } } ;
652657
653- ( $expr: expr, label = $label: literal , log = true , capacity = $capacity: expr) => { {
658+ ( $expr: expr, label = $label: expr , log = true , capacity = $capacity: expr) => { {
654659 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
655660 const _: usize = $capacity;
656- $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label) , Some ( $capacity) )
661+ $crate:: InstrumentLog :: instrument_log(
662+ $expr,
663+ CHANNEL_ID ,
664+ Some ( $label. to_string( ) ) ,
665+ Some ( $capacity) ,
666+ )
657667 } } ;
658668
659- ( $expr: expr, capacity = $capacity: expr, label = $label: literal , log = true ) => { {
669+ ( $expr: expr, capacity = $capacity: expr, label = $label: expr , log = true ) => { {
660670 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
661671 const _: usize = $capacity;
662- $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label) , Some ( $capacity) )
672+ $crate:: InstrumentLog :: instrument_log(
673+ $expr,
674+ CHANNEL_ID ,
675+ Some ( $label. to_string( ) ) ,
676+ Some ( $capacity) ,
677+ )
663678 } } ;
664679
665- ( $expr: expr, capacity = $capacity: expr, log = true , label = $label: literal ) => { {
680+ ( $expr: expr, capacity = $capacity: expr, log = true , label = $label: expr ) => { {
666681 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
667682 const _: usize = $capacity;
668- $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label) , Some ( $capacity) )
683+ $crate:: InstrumentLog :: instrument_log(
684+ $expr,
685+ CHANNEL_ID ,
686+ Some ( $label. to_string( ) ) ,
687+ Some ( $capacity) ,
688+ )
669689 } } ;
670690
671- ( $expr: expr, log = true , label = $label: literal , capacity = $capacity: expr) => { {
691+ ( $expr: expr, log = true , label = $label: expr , capacity = $capacity: expr) => { {
672692 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
673693 const _: usize = $capacity;
674- $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label) , Some ( $capacity) )
694+ $crate:: InstrumentLog :: instrument_log(
695+ $expr,
696+ CHANNEL_ID ,
697+ Some ( $label. to_string( ) ) ,
698+ Some ( $capacity) ,
699+ )
675700 } } ;
676701
677- ( $expr: expr, log = true , capacity = $capacity: expr, label = $label: literal ) => { {
702+ ( $expr: expr, log = true , capacity = $capacity: expr, label = $label: expr ) => { {
678703 const CHANNEL_ID : & ' static str = concat!( file!( ) , ":" , line!( ) ) ;
679704 const _: usize = $capacity;
680- $crate:: InstrumentLog :: instrument_log( $expr, CHANNEL_ID , Some ( $label) , Some ( $capacity) )
705+ $crate:: InstrumentLog :: instrument_log(
706+ $expr,
707+ CHANNEL_ID ,
708+ Some ( $label. to_string( ) ) ,
709+ Some ( $capacity) ,
710+ )
681711 } } ;
682712}
683713
@@ -697,8 +727,9 @@ fn compare_channel_stats(a: &ChannelStats, b: &ChannelStats) -> std::cmp::Orderi
697727 ( false , true ) => std:: cmp:: Ordering :: Greater ,
698728 ( true , true ) => a
699729 . label
730+ . as_ref ( )
700731 . unwrap ( )
701- . cmp ( b. label . unwrap ( ) )
732+ . cmp ( b. label . as_ref ( ) . unwrap ( ) )
702733 . then_with ( || a. iter . cmp ( & b. iter ) ) ,
703734 ( false , false ) => a. source . cmp ( b. source ) . then_with ( || a. iter . cmp ( & b. iter ) ) ,
704735 }
0 commit comments