@@ -13,7 +13,7 @@ use serde::{
1313use crate :: ValidError ;
1414
1515// In practice, this may need to be raised all the way up to 4096.
16- pub ( crate ) const MAX_BENCHMARK_NAME_LEN : usize = 1024 ;
16+ const MAX_BENCHMARK_NAME_LEN : usize = 1024 ;
1717
1818const BENCHER_IGNORE_SNAKE_CASE : & str = "_bencher_ignore" ;
1919const BENCHER_IGNORE_PASCAL_CASE : & str = "BencherIgnore" ;
@@ -30,18 +30,18 @@ pub struct BenchmarkName(String);
3030crate :: typed_string!( BenchmarkName ) ;
3131
3232impl BenchmarkName {
33+ pub const MAX_LEN : usize = MAX_BENCHMARK_NAME_LEN ;
34+
3335 pub fn try_push ( & mut self , separator : char , other : & Self ) -> Result < ( ) , ValidError > {
34- let remaining_capacity = MAX_BENCHMARK_NAME_LEN
35- . checked_sub ( self . 0 . len ( ) )
36- . unwrap_or_default ( ) ;
36+ let remaining_capacity = Self :: MAX_LEN . checked_sub ( self . 0 . len ( ) ) . unwrap_or_default ( ) ;
3737 if other. 0 . len ( ) < remaining_capacity {
3838 self . 0 . push ( separator) ;
3939 self . 0 . push_str ( other. as_ref ( ) ) ;
4040 debug_assert ! (
41- self . 0 . len( ) <= MAX_BENCHMARK_NAME_LEN ,
41+ self . 0 . len( ) <= Self :: MAX_LEN ,
4242 "Benchmark name length is {} but should be <= {}" ,
4343 self . 0 . len( ) ,
44- MAX_BENCHMARK_NAME_LEN
44+ Self :: MAX_LEN
4545 ) ;
4646 Ok ( ( ) )
4747 } else {
@@ -122,7 +122,7 @@ mod test {
122122
123123 use crate :: BenchmarkName ;
124124
125- use super :: { is_valid_benchmark_name, MAX_BENCHMARK_NAME_LEN } ;
125+ use super :: is_valid_benchmark_name;
126126 use pretty_assertions:: assert_eq;
127127
128128 #[ test]
@@ -142,8 +142,8 @@ mod test {
142142 let benchmark_name_len = benchmark_name. 0 . len ( ) ;
143143 assert_eq ! ( benchmark_name_len, 10 ) ;
144144
145- let other_benchmark_name_bytes: [ u8 ; MAX_BENCHMARK_NAME_LEN - 11 ] =
146- [ 0 ; MAX_BENCHMARK_NAME_LEN - 11 ] ;
145+ let other_benchmark_name_bytes: [ u8 ; BenchmarkName :: MAX_LEN - 11 ] =
146+ [ 0 ; BenchmarkName :: MAX_LEN - 11 ] ;
147147 let other_benchmark_name: BenchmarkName = std:: str:: from_utf8 ( & other_benchmark_name_bytes)
148148 . unwrap ( )
149149 . parse ( )
@@ -153,11 +153,11 @@ mod test {
153153 // 10 + 1 + 1013 = 1024
154154 assert_eq ! (
155155 benchmark_name_len + 1 + other_benchmark_name_len,
156- MAX_BENCHMARK_NAME_LEN
156+ BenchmarkName :: MAX_LEN
157157 ) ;
158158
159159 benchmark_name. try_push ( '.' , & other_benchmark_name) . unwrap ( ) ;
160- assert_eq ! ( benchmark_name. 0 . len( ) , MAX_BENCHMARK_NAME_LEN ) ;
160+ assert_eq ! ( benchmark_name. 0 . len( ) , BenchmarkName :: MAX_LEN ) ;
161161 is_valid_benchmark_name ( & benchmark_name. 0 ) ;
162162 assert_eq ! ( other_benchmark_name_len, other_benchmark_name. 0 . len( ) ) ;
163163 }
@@ -168,8 +168,8 @@ mod test {
168168 let benchmark_name_len = benchmark_name. 0 . len ( ) ;
169169 assert_eq ! ( benchmark_name_len, 10 ) ;
170170
171- let other_benchmark_name_bytes: [ u8 ; MAX_BENCHMARK_NAME_LEN - 10 ] =
172- [ 0 ; MAX_BENCHMARK_NAME_LEN - 10 ] ;
171+ let other_benchmark_name_bytes: [ u8 ; BenchmarkName :: MAX_LEN - 10 ] =
172+ [ 0 ; BenchmarkName :: MAX_LEN - 10 ] ;
173173 let other_benchmark_name: BenchmarkName = std:: str:: from_utf8 ( & other_benchmark_name_bytes)
174174 . unwrap ( )
175175 . parse ( )
@@ -179,7 +179,7 @@ mod test {
179179 // 10 + 1 + 1014 = 1025
180180 assert_eq ! (
181181 benchmark_name_len + 1 + other_benchmark_name_len,
182- MAX_BENCHMARK_NAME_LEN + 1
182+ BenchmarkName :: MAX_LEN + 1
183183 ) ;
184184
185185 assert ! ( benchmark_name. try_push( '.' , & other_benchmark_name) . is_err( ) ) ;
0 commit comments