@@ -4,7 +4,6 @@ use lookup::lookup_v2::ConfigTargetPath;
44use serde_json;
55use std:: borrow:: Cow ;
66use std:: collections:: BTreeMap ;
7- use std:: fmt:: Write ;
87use std:: str:: FromStr ;
98use strum:: { EnumString , FromRepr , VariantNames } ;
109use tokio_util:: codec:: Encoder ;
@@ -235,8 +234,9 @@ where
235234 None => Cow :: Borrowed ( s) , // All valid, zero allocation
236235 Some ( ( first_invalid_idx, _) ) => {
237236 let mut result = String :: with_capacity ( s. len ( ) ) ;
238- result. push_str ( & s[ ..first_invalid_idx] ) ; // Copy valid prefix
239- for c in s[ first_invalid_idx..] . chars ( ) {
237+ let ( valid_prefix, remainder) = s. split_at ( first_invalid_idx) ;
238+ result. push_str ( valid_prefix) ;
239+ for c in remainder. chars ( ) {
240240 result. push ( if is_valid ( c) { c } else { '_' } ) ;
241241 }
242242
@@ -320,7 +320,7 @@ impl SyslogMessage {
320320 fn encode ( & self , rfc : & SyslogRFC ) -> String {
321321 let mut result = String :: with_capacity ( 256 ) ;
322322
323- let _ = write ! ( result, "{}" , self . pri. encode( ) ) ;
323+ result. push_str ( & self . pri . encode ( ) . to_string ( ) ) ;
324324
325325 if * rfc == SyslogRFC :: Rfc5424 {
326326 result. push_str ( SYSLOG_V1 ) ;
@@ -329,7 +329,7 @@ impl SyslogMessage {
329329
330330 match rfc {
331331 SyslogRFC :: Rfc3164 => {
332- let _ = write ! ( result , "{} " , self . timestamp. format( "%b %e %H:%M:%S" ) ) ;
332+ result . push_str ( & format ! ( "{} " , self . timestamp. format( "%b %e %H:%M:%S" ) ) ) ;
333333 }
334334 SyslogRFC :: Rfc5424 => {
335335 result. push_str (
@@ -435,12 +435,12 @@ impl StructuredData {
435435 self . elements
436436 . iter ( )
437437 . fold ( String :: new ( ) , |mut acc, ( sd_id, sd_params) | {
438- let _ = write ! ( acc , "[{sd_id}" ) ;
438+ acc . push_str ( & format ! ( "[{sd_id}" ) ) ;
439439 for ( key, value) in sd_params {
440440 let esc_val = escape_sd_value ( value) ;
441- let _ = write ! ( acc , " {key}=\" {esc_val}\" " ) ;
441+ acc . push_str ( & format ! ( " {key}=\" {esc_val}\" " ) ) ;
442442 }
443- let _ = write ! ( acc, "]" ) ;
443+ acc. push ( ']' ) ;
444444 acc
445445 } )
446446 }
0 commit comments