@@ -11,9 +11,7 @@ use std::str::from_utf8_unchecked;
1111use super :: code;
1212use super :: prelude:: * ;
1313
14- fn c_string ( value : & str ) -> Bytes {
15- Bytes :: from ( [ value. as_bytes ( ) , b"\0 " ] . concat ( ) )
16- }
14+ use super :: c_string_bytes;
1715
1816/// Parse (F) message.
1917#[ derive( Clone , Hash , Eq , PartialEq , Default ) ]
@@ -48,17 +46,17 @@ impl Parse {
4846 pub fn new_anonymous ( query : & str ) -> Self {
4947 Self {
5048 name : Bytes :: from ( "\0 " ) ,
51- query : c_string ( query) ,
49+ query : c_string_bytes ( query) ,
5250 data_types : Bytes :: copy_from_slice ( & 0i16 . to_be_bytes ( ) ) ,
5351 original : None ,
5452 }
5553 }
5654
5755 /// New prepared statement.
58- pub fn named ( name : impl ToString , query : impl ToString ) -> Self {
56+ pub fn named ( name : impl AsRef < str > , query : impl AsRef < str > ) -> Self {
5957 Self {
60- name : c_string ( & name. to_string ( ) ) ,
61- query : c_string ( & query. to_string ( ) ) ,
58+ name : c_string_bytes ( name. as_ref ( ) ) ,
59+ query : c_string_bytes ( query. as_ref ( ) ) ,
6260 data_types : Bytes :: copy_from_slice ( & 0i16 . to_be_bytes ( ) ) ,
6361 original : None ,
6462 }
@@ -90,16 +88,16 @@ impl Parse {
9088 // won't pin any original buffers (allowing to modify them without new allocation)
9189 // and the new allocation memory size will be just limited by the actual data, not buffers
9290 Parse {
93- name : c_string ( name) ,
91+ name : c_string_bytes ( name) ,
9492 query : Bytes :: copy_from_slice ( & self . query ) ,
9593 data_types : Bytes :: copy_from_slice ( & self . data_types ) ,
9694 original : None ,
9795 }
9896 }
9997
10098 /// Rename the prepared statement with minimal allocations.
101- pub fn rename ( & mut self , name : & str ) {
102- self . name = c_string ( name) ;
99+ pub fn rename ( & mut self , name : impl AsRef < str > ) {
100+ self . name = c_string_bytes ( name. as_ref ( ) ) ;
103101 self . original = None ;
104102 }
105103
@@ -116,7 +114,7 @@ impl Parse {
116114
117115 /// Update the SQL for this prepared statement.
118116 pub fn set_query ( & mut self , query : & str ) {
119- self . query = c_string ( query) ;
117+ self . query = c_string_bytes ( query) ;
120118 self . original = None ;
121119 }
122120
0 commit comments