@@ -22,7 +22,7 @@ use json;
2222
2323use crate :: backend:: BackendImpl ;
2424use crate :: pyroscope:: Compression :: GZIP ;
25- use crate :: pyroscope:: ReportEncoding :: { PPROF } ;
25+ use crate :: pyroscope:: ReportEncoding :: PPROF ;
2626
2727const LOG_TAG : & str = "Pyroscope::Agent" ;
2828
@@ -102,7 +102,7 @@ impl PyroscopeConfig {
102102 spy_name : String :: from ( "undefined" ) , // Spy Name should be set by the backend
103103 auth_token : None , // No authentication token
104104 basic_auth : None ,
105- func : None , // No function
105+ func : None , // No function
106106 compression : None ,
107107 report_encoding : ReportEncoding :: FOLDED ,
108108 tenant_id : None ,
@@ -139,7 +139,6 @@ impl PyroscopeConfig {
139139 Self { spy_name, ..self }
140140 }
141141
142-
143142 pub fn auth_token ( self , auth_token : String ) -> Self {
144143 Self {
145144 auth_token : Some ( auth_token) ,
@@ -185,7 +184,6 @@ impl PyroscopeConfig {
185184 }
186185 }
187186
188-
189187 /// Set the http request body compression.
190188 ///
191189 /// # Example
@@ -203,7 +201,7 @@ impl PyroscopeConfig {
203201
204202 pub fn report_encoding ( self , report_encoding : ReportEncoding ) -> Self {
205203 Self {
206- report_encoding : report_encoding ,
204+ report_encoding,
207205 ..self
208206 }
209207 }
@@ -217,7 +215,7 @@ impl PyroscopeConfig {
217215
218216 pub fn http_headers ( self , http_headers : HashMap < String , String > ) -> Self {
219217 Self {
220- http_headers : http_headers ,
218+ http_headers,
221219 ..self
222220 }
223221 }
@@ -328,7 +326,9 @@ impl PyroscopeAgentBuilder {
328326
329327 pub fn basic_auth ( self , username : impl AsRef < str > , password : impl AsRef < str > ) -> Self {
330328 Self {
331- config : self . config . basic_auth ( username. as_ref ( ) . to_owned ( ) , password. as_ref ( ) . to_owned ( ) ) ,
329+ config : self
330+ . config
331+ . basic_auth ( username. as_ref ( ) . to_owned ( ) , password. as_ref ( ) . to_owned ( ) ) ,
332332 ..self
333333 }
334334 }
@@ -455,7 +455,7 @@ impl PyroscopeAgentBuilder {
455455 handle : None ,
456456 running : Arc :: new ( (
457457 #[ allow( clippy:: mutex_atomic) ]
458- Mutex :: new ( false ) ,
458+ Mutex :: new ( false ) ,
459459 Condvar :: new ( ) ,
460460 ) ) ,
461461 _state : PhantomData ,
@@ -465,7 +465,7 @@ impl PyroscopeAgentBuilder {
465465
466466#[ derive( Clone , Debug ) ]
467467pub enum Compression {
468- GZIP
468+ GZIP ,
469469}
470470
471471impl FromStr for Compression {
@@ -843,31 +843,42 @@ pub fn parse_http_headers_json(http_headers_json: String) -> Result<HashMap<Stri
843843 let mut http_headers = HashMap :: new ( ) ;
844844 let parsed = json:: parse ( & http_headers_json) ?;
845845 if !parsed. is_object ( ) {
846- return Err ( PyroscopeError :: AdHoc ( format ! ( "expected object, got {}" , parsed) ) ) ;
846+ return Err ( PyroscopeError :: AdHoc ( format ! (
847+ "expected object, got {}" ,
848+ parsed
849+ ) ) ) ;
847850 }
848851 for ( k, v) in parsed. entries ( ) {
849852 if v. is_string ( ) {
850853 http_headers. insert ( k. to_string ( ) , v. to_string ( ) ) ;
851854 } else {
852- return Err ( PyroscopeError :: AdHoc ( format ! ( "invalid http header value, not a string: {}" , v. to_string( ) ) ) ) ;
855+ return Err ( PyroscopeError :: AdHoc ( format ! (
856+ "invalid http header value, not a string: {}" ,
857+ v
858+ ) ) ) ;
853859 }
854- } ;
855- return Ok ( http_headers) ;
860+ }
861+ Ok ( http_headers)
856862}
857863
858864pub fn parse_vec_string_json ( s : String ) -> Result < Vec < String > > {
859865 let parsed = json:: parse ( & s) ?;
860866 if !parsed. is_array ( ) {
861- return Err ( PyroscopeError :: AdHoc ( format ! ( "expected array, got {}" , parsed) ) ) ;
867+ return Err ( PyroscopeError :: AdHoc ( format ! (
868+ "expected array, got {}" ,
869+ parsed
870+ ) ) ) ;
862871 }
863- let mut res = Vec :: new ( ) ;
864- res. reserve ( parsed. len ( ) ) ;
872+ let mut res = Vec :: with_capacity ( parsed. len ( ) ) ;
865873 for v in parsed. members ( ) {
866874 if v. is_string ( ) {
867875 res. push ( v. to_string ( ) ) ;
868876 } else {
869- return Err ( PyroscopeError :: AdHoc ( format ! ( "invalid element value, not a string: {}" , v. to_string( ) ) ) ) ;
877+ return Err ( PyroscopeError :: AdHoc ( format ! (
878+ "invalid element value, not a string: {}" ,
879+ v
880+ ) ) ) ;
870881 }
871- } ;
872- return Ok ( res) ;
873- }
882+ }
883+ Ok ( res)
884+ }
0 commit comments