@@ -4,7 +4,6 @@ use serde::{Serialize, Serializer};
44use std:: fmt:: { self , Debug , Formatter } ;
55use std:: hash:: { Hash , Hasher } ;
66use std:: ops:: Deref ;
7- use std:: str;
87
98/// BytesFormat describes the format in which the string was expressed
109#[ derive( PartialEq , Eq , Copy , Clone ) ]
@@ -48,10 +47,12 @@ impl Serialize for BytesExpr {
4847 S : Serializer ,
4948 {
5049 match self . format ( ) {
51- BytesFormat :: Quoted | BytesFormat :: Raw ( _) => match std:: str:: from_utf8 ( & self . data ) {
52- Ok ( s) => s. serialize ( serializer) ,
53- Err ( _) => self . data . serialize ( serializer) ,
54- } ,
50+ BytesFormat :: Quoted | BytesFormat :: Raw ( _) => {
51+ match simdutf8:: basic:: from_utf8 ( & self . data ) {
52+ Ok ( s) => s. serialize ( serializer) ,
53+ Err ( _) => self . data . serialize ( serializer) ,
54+ }
55+ }
5556 BytesFormat :: Byte => self . data . serialize ( serializer) ,
5657 }
5758 }
@@ -117,10 +118,12 @@ impl Debug for BytesExpr {
117118 }
118119
119120 match self . format {
120- BytesFormat :: Quoted | BytesFormat :: Raw ( _) => match std:: str:: from_utf8 ( & self . data ) {
121- Ok ( s) => s. fmt ( f) ,
122- Err ( _) => fmt_raw ( & self . data , f) ,
123- } ,
121+ BytesFormat :: Quoted | BytesFormat :: Raw ( _) => {
122+ match simdutf8:: basic:: from_utf8 ( & self . data ) {
123+ Ok ( s) => s. fmt ( f) ,
124+ Err ( _) => fmt_raw ( & self . data , f) ,
125+ }
126+ }
124127 BytesFormat :: Byte => fmt_raw ( & self . data , f) ,
125128 }
126129 }
0 commit comments