@@ -97,7 +97,7 @@ pub fn sql_nonnull_to_json<'r>(mut get_ref: impl FnMut() -> sqlx::any::AnyValueR
9797 }
9898 "JSON" | "JSON[]" | "JSONB" | "JSONB[]" => decode_raw :: < Value > ( raw_value) ,
9999 "BLOB" | "BYTEA" | "FILESTREAM" | "VARBINARY" | "BIGVARBINARY" | "BINARY" | "IMAGE" => {
100- vec_to_data_uri_value ( decode_raw :: < Vec < u8 > > ( raw_value) )
100+ vec_to_data_uri_value ( & decode_raw :: < Vec < u8 > > ( raw_value) )
101101 }
102102 // Deserialize as a string by default
103103 _ => decode_raw :: < String > ( raw_value) . into ( ) ,
@@ -116,25 +116,25 @@ pub fn row_to_string(row: &AnyRow) -> Option<String> {
116116
117117/// Converts binary data to a data URL string.
118118/// This function is used by both SQL type conversion and file reading functions.
119- pub fn vec_to_data_uri ( bytes : Vec < u8 > ) -> String {
119+ pub fn vec_to_data_uri ( bytes : & [ u8 ] ) -> String {
120120 vec_to_data_uri_with_mime ( bytes, "application/octet-stream" )
121121}
122122
123123/// Converts binary data to a data URL string with a specific MIME type.
124124/// This function is used by both SQL type conversion and file reading functions.
125- pub fn vec_to_data_uri_with_mime ( bytes : Vec < u8 > , mime_type : & str ) -> String {
126- let mut data_url = format ! ( "data:{};base64," , mime_type ) ;
125+ pub fn vec_to_data_uri_with_mime ( bytes : & [ u8 ] , mime_type : & str ) -> String {
126+ let mut data_url = format ! ( "data:{mime_type };base64," ) ;
127127 base64:: Engine :: encode_string (
128128 & base64:: engine:: general_purpose:: STANDARD ,
129- & bytes,
129+ bytes,
130130 & mut data_url,
131131 ) ;
132132 data_url
133133}
134134
135135/// Converts binary data to a data URL JSON value.
136136/// This is a convenience function for SQL type conversion.
137- pub fn vec_to_data_uri_value ( bytes : Vec < u8 > ) -> Value {
137+ pub fn vec_to_data_uri_value ( bytes : & [ u8 ] ) -> Value {
138138 Value :: String ( vec_to_data_uri ( bytes) )
139139}
140140
@@ -478,41 +478,41 @@ mod tests {
478478 #[ test]
479479 fn test_vec_to_data_uri ( ) {
480480 // Test with empty bytes
481- let result = vec_to_data_uri ( vec ! [ ] ) ;
481+ let result = vec_to_data_uri ( & [ ] ) ;
482482 assert_eq ! ( result, "data:application/octet-stream;base64," ) ;
483483
484484 // Test with simple text
485- let result = vec_to_data_uri ( b"Hello World" . to_vec ( ) ) ;
485+ let result = vec_to_data_uri ( b"Hello World" ) ;
486486 assert_eq ! (
487487 result,
488488 "data:application/octet-stream;base64,SGVsbG8gV29ybGQ="
489489 ) ;
490490
491491 // Test with binary data
492- let binary_data = vec ! [ 0 , 1 , 2 , 255 , 254 , 253 ] ;
493- let result = vec_to_data_uri ( binary_data) ;
492+ let binary_data = [ 0 , 1 , 2 , 255 , 254 , 253 ] ;
493+ let result = vec_to_data_uri ( & binary_data) ;
494494 assert_eq ! ( result, "data:application/octet-stream;base64,AAEC//79" ) ;
495495 }
496496
497497 #[ test]
498498 fn test_vec_to_data_uri_with_mime ( ) {
499499 // Test with custom MIME type
500- let result = vec_to_data_uri_with_mime ( b"Hello" . to_vec ( ) , "text/plain" ) ;
500+ let result = vec_to_data_uri_with_mime ( b"Hello" , "text/plain" ) ;
501501 assert_eq ! ( result, "data:text/plain;base64,SGVsbG8=" ) ;
502502
503503 // Test with image MIME type
504- let result = vec_to_data_uri_with_mime ( vec ! [ 255 , 216 , 255 ] , "image/jpeg" ) ;
504+ let result = vec_to_data_uri_with_mime ( & [ 255 , 216 , 255 ] , "image/jpeg" ) ;
505505 assert_eq ! ( result, "data:image/jpeg;base64,/9j/" ) ;
506506
507507 // Test with empty bytes and custom MIME
508- let result = vec_to_data_uri_with_mime ( vec ! [ ] , "application/json" ) ;
508+ let result = vec_to_data_uri_with_mime ( & [ ] , "application/json" ) ;
509509 assert_eq ! ( result, "data:application/json;base64," ) ;
510510 }
511511
512512 #[ test]
513513 fn test_vec_to_data_uri_value ( ) {
514514 // Test that it returns a JSON string value
515- let result = vec_to_data_uri_value ( b"test" . to_vec ( ) ) ;
515+ let result = vec_to_data_uri_value ( b"test" ) ;
516516 match result {
517517 Value :: String ( s) => assert_eq ! ( s, "data:application/octet-stream;base64,dGVzdA==" ) ,
518518 _ => panic ! ( "Expected String value" ) ,
0 commit comments