@@ -31,11 +31,11 @@ pub struct ManagedStringId {
3131} 
3232
3333impl  ManagedStringId  { 
34-     pub  fn  empty ( )  -> Self  { 
34+     pub  const   fn  empty ( )  -> Self  { 
3535        Self :: new ( 0 ) 
3636    } 
3737
38-     pub  fn  new ( value :  u32 )  -> Self  { 
38+     pub  const   fn  new ( value :  u32 )  -> Self  { 
3939        ManagedStringId  {  value } 
4040    } 
4141} 
@@ -130,7 +130,7 @@ pub struct Label<'a> {
130130    pub  key :  & ' a  str , 
131131
132132    /// At most one of the following must be present 
133- pub  str :  Option < & ' a  str > , 
133+ pub  str :  & ' a  str , 
134134    pub  num :  i64 , 
135135
136136    /// Should only be present when num is present. 
@@ -140,7 +140,7 @@ pub struct Label<'a> {
140140/// Consumers may also  interpret units like "bytes" and "kilobytes" as memory 
141141/// units and units like "seconds" and "nanoseconds" as time units, 
142142/// and apply appropriate unit conversions to these. 
143- pub  num_unit :  Option < & ' a  str > , 
143+ pub  num_unit :  & ' a  str , 
144144} 
145145
146146#[ derive( Copy ,  Clone ,  Debug ,  Default ,  Eq ,  PartialEq ) ]  
@@ -149,16 +149,16 @@ pub struct StringIdLabel {
149149    pub  key :  ManagedStringId , 
150150
151151    /// At most one of the following must be present 
152- pub  str :  Option < ManagedStringId > , 
152+ pub  str :  ManagedStringId , 
153153    pub  num :  i64 , 
154154
155155    /// Should only be present when num is present. 
156- pub  num_unit :  Option < ManagedStringId > , 
156+ pub  num_unit :  ManagedStringId , 
157157} 
158158
159159impl  Label < ' _ >  { 
160160    pub  fn  uses_at_most_one_of_str_and_num ( & self )  -> bool  { 
161-         self . str . is_none ( )  || ( self . num  == 0  && self . num_unit . is_none ( ) ) 
161+         self . str . is_empty ( )  || ( self . num  == 0  && self . num_unit . is_empty ( ) ) 
162162    } 
163163} 
164164
@@ -400,17 +400,9 @@ impl<'a> TryFrom<&'a pprof::Profile> for Profile<'a> {
400400            for  label in  sample. labels . iter ( )  { 
401401                labels. push ( Label  { 
402402                    key :  string_table_fetch ( pprof,  label. key ) ?, 
403-                     str :  if  label. str  == 0  { 
404-                         None 
405-                     }  else  { 
406-                         Some ( string_table_fetch ( pprof,  label. str ) ?) 
407-                     } , 
403+                     str :  string_table_fetch ( pprof,  label. str ) ?, 
408404                    num :  label. num , 
409-                     num_unit :  if  label. num_unit  == 0  { 
410-                         None 
411-                     }  else  { 
412-                         Some ( string_table_fetch ( pprof,  label. num_unit ) ?) 
413-                     } , 
405+                     num_unit :  string_table_fetch ( pprof,  label. num_unit ) ?, 
414406                } ) 
415407            } 
416408            let  sample = Sample  { 
@@ -439,49 +431,49 @@ mod tests {
439431    fn  label_uses_at_most_one_of_str_and_num ( )  { 
440432        let  label = Label  { 
441433            key :  "name" , 
442-             str :  Some ( "levi" ) , 
434+             str :  "levi" , 
443435            num :  0 , 
444-             num_unit :  Some ( "name" ) ,  // can't use num_unit with str 
436+             num_unit :  "name" ,  // can't use num_unit with str 
445437        } ; 
446438        assert ! ( !label. uses_at_most_one_of_str_and_num( ) ) ; 
447439
448440        let  label = Label  { 
449441            key :  "name" , 
450-             str :  Some ( "levi" ) , 
442+             str :  "levi" , 
451443            num :  10 ,  // can't use num with str 
452-             num_unit :  None , 
444+             num_unit :  "" , 
453445        } ; 
454446        assert ! ( !label. uses_at_most_one_of_str_and_num( ) ) ; 
455447
456448        let  label = Label  { 
457449            key :  "name" , 
458-             str :  Some ( "levi" ) , 
450+             str :  "levi" , 
459451            num :  0 , 
460-             num_unit :  None , 
452+             num_unit :  "" , 
461453        } ; 
462454        assert ! ( label. uses_at_most_one_of_str_and_num( ) ) ; 
463455
464456        let  label = Label  { 
465457            key :  "process_id" , 
466-             str :  None , 
458+             str :  "" , 
467459            num :  0 , 
468-             num_unit :  None , 
460+             num_unit :  "" , 
469461        } ; 
470462        assert ! ( label. uses_at_most_one_of_str_and_num( ) ) ; 
471463
472464        let  label = Label  { 
473465            key :  "local root span id" , 
474-             str :  None , 
466+             str :  "" , 
475467            num :  10901 , 
476-             num_unit :  None , 
468+             num_unit :  "" , 
477469        } ; 
478470        assert ! ( label. uses_at_most_one_of_str_and_num( ) ) ; 
479471
480472        let  label = Label  { 
481473            key :  "duration" , 
482-             str :  None , 
474+             str :  "" , 
483475            num :  12345 , 
484-             num_unit :  Some ( "nanoseconds" ) , 
476+             num_unit :  "nanoseconds" , 
485477        } ; 
486478        assert ! ( label. uses_at_most_one_of_str_and_num( ) ) ; 
487479    } 
0 commit comments