@@ -14,7 +14,7 @@ use embedded_svc::ipv4::{IpAddr, Ipv4Addr, Ipv6Addr};
1414
1515use esp_idf_sys:: * ;
1616
17- use crate :: private:: cstr:: try_cstring_new ;
17+ use crate :: private:: cstr:: to_cstring_arg ;
1818use crate :: private:: cstr:: CStr ;
1919use crate :: private:: mutex:: { Mutex , RawMutex } ;
2020
@@ -151,13 +151,13 @@ impl EspMdns {
151151 }
152152
153153 pub fn set_hostname ( & mut self , hostname : impl AsRef < str > ) -> Result < ( ) , EspError > {
154- let hostname = try_cstring_new ( hostname. as_ref ( ) ) ?;
154+ let hostname = to_cstring_arg ( hostname. as_ref ( ) ) ?;
155155
156156 esp ! ( unsafe { mdns_hostname_set( hostname. as_ptr( ) ) } )
157157 }
158158
159159 pub fn set_instance_name ( & mut self , instance_name : impl AsRef < str > ) -> Result < ( ) , EspError > {
160- let instance_name = try_cstring_new ( instance_name. as_ref ( ) ) ?;
160+ let instance_name = to_cstring_arg ( instance_name. as_ref ( ) ) ?;
161161
162162 esp ! ( unsafe { mdns_instance_name_set( instance_name. as_ptr( ) ) } )
163163 }
@@ -171,17 +171,17 @@ impl EspMdns {
171171 txt : & [ ( & str , & str ) ] ,
172172 ) -> Result < ( ) , EspError > {
173173 let instance_name = if let Some ( instance_name) = instance_name {
174- Some ( try_cstring_new ( instance_name) ?)
174+ Some ( to_cstring_arg ( instance_name) ?)
175175 } else {
176176 None
177177 } ;
178- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
179- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
178+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
179+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
180180 let mut txtcstr = Vec :: with_capacity ( txt. len ( ) ) ;
181181 let mut txtptr = Vec :: with_capacity ( txt. len ( ) ) ;
182182 for e in txt. iter ( ) {
183- let key = try_cstring_new ( e. 0 ) ?;
184- let value = try_cstring_new ( e. 1 ) ?;
183+ let key = to_cstring_arg ( e. 0 ) ?;
184+ let value = to_cstring_arg ( e. 1 ) ?;
185185 txtptr. push ( mdns_txt_item_t {
186186 key : key. as_ptr ( ) ,
187187 value : value. as_ptr ( ) ,
@@ -209,8 +209,8 @@ impl EspMdns {
209209 proto : impl AsRef < str > ,
210210 port : u16 ,
211211 ) -> Result < ( ) , EspError > {
212- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
213- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
212+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
213+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
214214
215215 esp ! ( unsafe { mdns_service_port_set( service_type. as_ptr( ) , proto. as_ptr( ) , port) } )
216216 }
@@ -221,9 +221,9 @@ impl EspMdns {
221221 proto : impl AsRef < str > ,
222222 instance_name : impl AsRef < str > ,
223223 ) -> Result < ( ) , EspError > {
224- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
225- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
226- let instance_name = try_cstring_new ( instance_name. as_ref ( ) ) ?;
224+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
225+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
226+ let instance_name = to_cstring_arg ( instance_name. as_ref ( ) ) ?;
227227
228228 esp ! ( unsafe {
229229 mdns_service_instance_name_set(
@@ -241,10 +241,10 @@ impl EspMdns {
241241 key : impl AsRef < str > ,
242242 value : impl AsRef < str > ,
243243 ) -> Result < ( ) , EspError > {
244- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
245- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
246- let key = try_cstring_new ( key. as_ref ( ) ) ?;
247- let value = try_cstring_new ( value. as_ref ( ) ) ?;
244+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
245+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
246+ let key = to_cstring_arg ( key. as_ref ( ) ) ?;
247+ let value = to_cstring_arg ( value. as_ref ( ) ) ?;
248248
249249 esp ! ( unsafe {
250250 mdns_service_txt_item_set(
@@ -262,9 +262,9 @@ impl EspMdns {
262262 proto : impl AsRef < str > ,
263263 key : impl AsRef < str > ,
264264 ) -> Result < ( ) , EspError > {
265- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
266- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
267- let key = try_cstring_new ( key. as_ref ( ) ) ?;
265+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
266+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
267+ let key = to_cstring_arg ( key. as_ref ( ) ) ?;
268268
269269 esp ! ( unsafe {
270270 mdns_service_txt_item_remove( service_type. as_ptr( ) , proto. as_ptr( ) , key. as_ptr( ) )
@@ -277,15 +277,15 @@ impl EspMdns {
277277 proto : impl AsRef < str > ,
278278 txt : & [ ( & str , & str ) ] ,
279279 ) -> Result < ( ) , EspError > {
280- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
281- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
280+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
281+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
282282
283283 let mut txtcstr = Vec :: with_capacity ( txt. len ( ) ) ;
284284 let mut txtptr = Vec :: with_capacity ( txt. len ( ) ) ;
285285
286286 for e in txt. iter ( ) {
287- let key = try_cstring_new ( e. 0 ) ?;
288- let value = try_cstring_new ( e. 1 ) ?;
287+ let key = to_cstring_arg ( e. 0 ) ?;
288+ let value = to_cstring_arg ( e. 1 ) ?;
289289 txtptr. push ( mdns_txt_item_t {
290290 key : key. as_ptr ( ) ,
291291 value : value. as_ptr ( ) ,
@@ -308,8 +308,8 @@ impl EspMdns {
308308 service_type : impl AsRef < str > ,
309309 proto : impl AsRef < str > ,
310310 ) -> Result < ( ) , EspError > {
311- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
312- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
311+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
312+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
313313
314314 esp ! ( unsafe { mdns_service_remove( service_type. as_ptr( ) , proto. as_ptr( ) ) } )
315315 }
@@ -330,17 +330,17 @@ impl EspMdns {
330330 results : & mut [ QueryResult ] ,
331331 ) -> Result < usize , EspError > {
332332 let name = if let Some ( name) = name {
333- Some ( try_cstring_new ( name) ?)
333+ Some ( to_cstring_arg ( name) ?)
334334 } else {
335335 None
336336 } ;
337337 let service_type = if let Some ( service_type) = service_type {
338- Some ( try_cstring_new ( service_type) ?)
338+ Some ( to_cstring_arg ( service_type) ?)
339339 } else {
340340 None
341341 } ;
342342 let proto = if let Some ( proto) = proto {
343- Some ( try_cstring_new ( proto) ?)
343+ Some ( to_cstring_arg ( proto) ?)
344344 } else {
345345 None
346346 } ;
@@ -370,7 +370,7 @@ impl EspMdns {
370370 hostname : impl AsRef < str > ,
371371 timeout : Duration ,
372372 ) -> Result < Ipv4Addr , EspError > {
373- let hostname = try_cstring_new ( hostname. as_ref ( ) ) ?;
373+ let hostname = to_cstring_arg ( hostname. as_ref ( ) ) ?;
374374 let mut addr: esp_ip4_addr_t = Default :: default ( ) ;
375375
376376 esp ! ( unsafe { mdns_query_a( hostname. as_ptr( ) , timeout. as_millis( ) as _, & mut addr) } ) ?;
@@ -383,7 +383,7 @@ impl EspMdns {
383383 hostname : impl AsRef < str > ,
384384 timeout : Duration ,
385385 ) -> Result < Ipv6Addr , EspError > {
386- let hostname = try_cstring_new ( hostname. as_ref ( ) ) ?;
386+ let hostname = to_cstring_arg ( hostname. as_ref ( ) ) ?;
387387 let mut addr: esp_ip6_addr_t = Default :: default ( ) ;
388388
389389 esp ! ( unsafe { mdns_query_aaaa( hostname. as_ptr( ) , timeout. as_millis( ) as _, & mut addr) } ) ?;
@@ -399,9 +399,9 @@ impl EspMdns {
399399 timeout : Duration ,
400400 results : & mut [ QueryResult ] ,
401401 ) -> Result < usize , EspError > {
402- let instance_name = try_cstring_new ( instance_name. as_ref ( ) ) ?;
403- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
404- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
402+ let instance_name = to_cstring_arg ( instance_name. as_ref ( ) ) ?;
403+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
404+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
405405 let mut result = core:: ptr:: null_mut ( ) ;
406406
407407 esp ! ( unsafe {
@@ -428,9 +428,9 @@ impl EspMdns {
428428 timeout : Duration ,
429429 results : & mut [ QueryResult ] ,
430430 ) -> Result < usize , EspError > {
431- let instance_name = try_cstring_new ( instance_name. as_ref ( ) ) ?;
432- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
433- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
431+ let instance_name = to_cstring_arg ( instance_name. as_ref ( ) ) ?;
432+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
433+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
434434 let mut result = core:: ptr:: null_mut ( ) ;
435435
436436 esp ! ( unsafe {
@@ -457,8 +457,8 @@ impl EspMdns {
457457 max_results : usize ,
458458 results : & mut [ QueryResult ] ,
459459 ) -> Result < usize , EspError > {
460- let service_type = try_cstring_new ( service_type. as_ref ( ) ) ?;
461- let proto = try_cstring_new ( proto. as_ref ( ) ) ?;
460+ let service_type = to_cstring_arg ( service_type. as_ref ( ) ) ?;
461+ let proto = to_cstring_arg ( proto. as_ref ( ) ) ?;
462462 let mut result = core:: ptr:: null_mut ( ) ;
463463
464464 esp ! ( unsafe {
0 commit comments