@@ -240,6 +240,13 @@ impl AsRef<str> for MetaMethod {
240
240
}
241
241
}
242
242
243
+ impl From < MetaMethod > for StdString {
244
+ #[ inline]
245
+ fn from ( method : MetaMethod ) -> Self {
246
+ method. name ( ) . to_owned ( )
247
+ }
248
+ }
249
+
243
250
/// Method registry for [`UserData`] implementors.
244
251
pub trait UserDataMethods < T > {
245
252
/// Add a regular method which accepts a `&T` as the first parameter.
@@ -249,7 +256,7 @@ pub trait UserDataMethods<T> {
249
256
///
250
257
/// If `add_meta_method` is used to set the `__index` metamethod, the `__index` metamethod will
251
258
/// be used as a fall-back if no regular method is found.
252
- fn add_method < M , A , R > ( & mut self , name : impl ToString , method : M )
259
+ fn add_method < M , A , R > ( & mut self , name : impl Into < StdString > , method : M )
253
260
where
254
261
M : Fn ( & Lua , & T , A ) -> Result < R > + MaybeSend + ' static ,
255
262
A : FromLuaMulti ,
@@ -260,7 +267,7 @@ pub trait UserDataMethods<T> {
260
267
/// Refer to [`add_method`] for more information about the implementation.
261
268
///
262
269
/// [`add_method`]: UserDataMethods::add_method
263
- fn add_method_mut < M , A , R > ( & mut self , name : impl ToString , method : M )
270
+ fn add_method_mut < M , A , R > ( & mut self , name : impl Into < StdString > , method : M )
264
271
where
265
272
M : FnMut ( & Lua , & mut T , A ) -> Result < R > + MaybeSend + ' static ,
266
273
A : FromLuaMulti ,
@@ -273,7 +280,7 @@ pub trait UserDataMethods<T> {
273
280
/// [`add_method`]: UserDataMethods::add_method
274
281
#[ cfg( feature = "async" ) ]
275
282
#[ cfg_attr( docsrs, doc( cfg( feature = "async" ) ) ) ]
276
- fn add_async_method < M , A , MR , R > ( & mut self , name : impl ToString , method : M )
283
+ fn add_async_method < M , A , MR , R > ( & mut self , name : impl Into < StdString > , method : M )
277
284
where
278
285
T : ' static ,
279
286
M : Fn ( Lua , UserDataRef < T > , A ) -> MR + MaybeSend + ' static ,
@@ -288,7 +295,7 @@ pub trait UserDataMethods<T> {
288
295
/// [`add_method`]: UserDataMethods::add_method
289
296
#[ cfg( feature = "async" ) ]
290
297
#[ cfg_attr( docsrs, doc( cfg( feature = "async" ) ) ) ]
291
- fn add_async_method_mut < M , A , MR , R > ( & mut self , name : impl ToString , method : M )
298
+ fn add_async_method_mut < M , A , MR , R > ( & mut self , name : impl Into < StdString > , method : M )
292
299
where
293
300
T : ' static ,
294
301
M : Fn ( Lua , UserDataRefMut < T > , A ) -> MR + MaybeSend + ' static ,
@@ -301,7 +308,7 @@ pub trait UserDataMethods<T> {
301
308
/// The first argument will be a [`AnyUserData`] of type `T` if the method is called with Lua
302
309
/// method syntax: `my_userdata:my_method(arg1, arg2)`, or it is passed in as the first
303
310
/// argument: `my_userdata.my_method(my_userdata, arg1, arg2)`.
304
- fn add_function < F , A , R > ( & mut self , name : impl ToString , function : F )
311
+ fn add_function < F , A , R > ( & mut self , name : impl Into < StdString > , function : F )
305
312
where
306
313
F : Fn ( & Lua , A ) -> Result < R > + MaybeSend + ' static ,
307
314
A : FromLuaMulti ,
@@ -312,7 +319,7 @@ pub trait UserDataMethods<T> {
312
319
/// This is a version of [`add_function`] that accepts a `FnMut` argument.
313
320
///
314
321
/// [`add_function`]: UserDataMethods::add_function
315
- fn add_function_mut < F , A , R > ( & mut self , name : impl ToString , function : F )
322
+ fn add_function_mut < F , A , R > ( & mut self , name : impl Into < StdString > , function : F )
316
323
where
317
324
F : FnMut ( & Lua , A ) -> Result < R > + MaybeSend + ' static ,
318
325
A : FromLuaMulti ,
@@ -326,7 +333,7 @@ pub trait UserDataMethods<T> {
326
333
/// [`add_function`]: UserDataMethods::add_function
327
334
#[ cfg( feature = "async" ) ]
328
335
#[ cfg_attr( docsrs, doc( cfg( feature = "async" ) ) ) ]
329
- fn add_async_function < F , A , FR , R > ( & mut self , name : impl ToString , function : F )
336
+ fn add_async_function < F , A , FR , R > ( & mut self , name : impl Into < StdString > , function : F )
330
337
where
331
338
F : Fn ( Lua , A ) -> FR + MaybeSend + ' static ,
332
339
A : FromLuaMulti ,
@@ -341,7 +348,7 @@ pub trait UserDataMethods<T> {
341
348
/// side has a metatable. To prevent this, use [`add_meta_function`].
342
349
///
343
350
/// [`add_meta_function`]: UserDataMethods::add_meta_function
344
- fn add_meta_method < M , A , R > ( & mut self , name : impl ToString , method : M )
351
+ fn add_meta_method < M , A , R > ( & mut self , name : impl Into < StdString > , method : M )
345
352
where
346
353
M : Fn ( & Lua , & T , A ) -> Result < R > + MaybeSend + ' static ,
347
354
A : FromLuaMulti ,
@@ -355,7 +362,7 @@ pub trait UserDataMethods<T> {
355
362
/// side has a metatable. To prevent this, use [`add_meta_function`].
356
363
///
357
364
/// [`add_meta_function`]: UserDataMethods::add_meta_function
358
- fn add_meta_method_mut < M , A , R > ( & mut self , name : impl ToString , method : M )
365
+ fn add_meta_method_mut < M , A , R > ( & mut self , name : impl Into < StdString > , method : M )
359
366
where
360
367
M : FnMut ( & Lua , & mut T , A ) -> Result < R > + MaybeSend + ' static ,
361
368
A : FromLuaMulti ,
@@ -371,7 +378,7 @@ pub trait UserDataMethods<T> {
371
378
docsrs,
372
379
doc( cfg( all( feature = "async" , not( any( feature = "lua51" , feature = "luau" ) ) ) ) )
373
380
) ]
374
- fn add_async_meta_method < M , A , MR , R > ( & mut self , name : impl ToString , method : M )
381
+ fn add_async_meta_method < M , A , MR , R > ( & mut self , name : impl Into < StdString > , method : M )
375
382
where
376
383
T : ' static ,
377
384
M : Fn ( Lua , UserDataRef < T > , A ) -> MR + MaybeSend + ' static ,
@@ -387,7 +394,7 @@ pub trait UserDataMethods<T> {
387
394
/// [`add_meta_method_mut`]: UserDataMethods::add_meta_method_mut
388
395
#[ cfg( all( feature = "async" , not( any( feature = "lua51" , feature = "luau" ) ) ) ) ]
389
396
#[ cfg_attr( docsrs, doc( cfg( feature = "async" ) ) ) ]
390
- fn add_async_meta_method_mut < M , A , MR , R > ( & mut self , name : impl ToString , method : M )
397
+ fn add_async_meta_method_mut < M , A , MR , R > ( & mut self , name : impl Into < StdString > , method : M )
391
398
where
392
399
T : ' static ,
393
400
M : Fn ( Lua , UserDataRefMut < T > , A ) -> MR + MaybeSend + ' static ,
@@ -400,7 +407,7 @@ pub trait UserDataMethods<T> {
400
407
/// Metamethods for binary operators can be triggered if either the left or right argument to
401
408
/// the binary operator has a metatable, so the first argument here is not necessarily a
402
409
/// userdata of type `T`.
403
- fn add_meta_function < F , A , R > ( & mut self , name : impl ToString , function : F )
410
+ fn add_meta_function < F , A , R > ( & mut self , name : impl Into < StdString > , function : F )
404
411
where
405
412
F : Fn ( & Lua , A ) -> Result < R > + MaybeSend + ' static ,
406
413
A : FromLuaMulti ,
@@ -411,7 +418,7 @@ pub trait UserDataMethods<T> {
411
418
/// This is a version of [`add_meta_function`] that accepts a `FnMut` argument.
412
419
///
413
420
/// [`add_meta_function`]: UserDataMethods::add_meta_function
414
- fn add_meta_function_mut < F , A , R > ( & mut self , name : impl ToString , function : F )
421
+ fn add_meta_function_mut < F , A , R > ( & mut self , name : impl Into < StdString > , function : F )
415
422
where
416
423
F : FnMut ( & Lua , A ) -> Result < R > + MaybeSend + ' static ,
417
424
A : FromLuaMulti ,
@@ -427,7 +434,7 @@ pub trait UserDataMethods<T> {
427
434
docsrs,
428
435
doc( cfg( all( feature = "async" , not( any( feature = "lua51" , feature = "luau" ) ) ) ) )
429
436
) ]
430
- fn add_async_meta_function < F , A , FR , R > ( & mut self , name : impl ToString , function : F )
437
+ fn add_async_meta_function < F , A , FR , R > ( & mut self , name : impl Into < StdString > , function : F )
431
438
where
432
439
F : Fn ( Lua , A ) -> FR + MaybeSend + ' static ,
433
440
A : FromLuaMulti ,
@@ -446,7 +453,7 @@ pub trait UserDataFields<T> {
446
453
///
447
454
/// If `add_meta_method` is used to set the `__index` metamethod, it will
448
455
/// be used as a fall-back if no regular field or method are found.
449
- fn add_field < V > ( & mut self , name : impl ToString , value : V )
456
+ fn add_field < V > ( & mut self , name : impl Into < StdString > , value : V )
450
457
where
451
458
V : IntoLua + ' static ;
452
459
@@ -457,7 +464,7 @@ pub trait UserDataFields<T> {
457
464
///
458
465
/// If `add_meta_method` is used to set the `__index` metamethod, the `__index` metamethod will
459
466
/// be used as a fall-back if no regular field or method are found.
460
- fn add_field_method_get < M , R > ( & mut self , name : impl ToString , method : M )
467
+ fn add_field_method_get < M , R > ( & mut self , name : impl Into < StdString > , method : M )
461
468
where
462
469
M : Fn ( & Lua , & T ) -> Result < R > + MaybeSend + ' static ,
463
470
R : IntoLua ;
@@ -470,21 +477,21 @@ pub trait UserDataFields<T> {
470
477
///
471
478
/// If `add_meta_method` is used to set the `__newindex` metamethod, the `__newindex` metamethod
472
479
/// will be used as a fall-back if no regular field is found.
473
- fn add_field_method_set < M , A > ( & mut self , name : impl ToString , method : M )
480
+ fn add_field_method_set < M , A > ( & mut self , name : impl Into < StdString > , method : M )
474
481
where
475
482
M : FnMut ( & Lua , & mut T , A ) -> Result < ( ) > + MaybeSend + ' static ,
476
483
A : FromLua ;
477
484
478
485
/// Add a regular field getter as a function which accepts a generic [`AnyUserData`] of type `T`
479
486
/// argument.
480
- fn add_field_function_get < F , R > ( & mut self , name : impl ToString , function : F )
487
+ fn add_field_function_get < F , R > ( & mut self , name : impl Into < StdString > , function : F )
481
488
where
482
489
F : Fn ( & Lua , AnyUserData ) -> Result < R > + MaybeSend + ' static ,
483
490
R : IntoLua ;
484
491
485
492
/// Add a regular field setter as a function which accepts a generic [`AnyUserData`] of type `T`
486
493
/// first argument.
487
- fn add_field_function_set < F , A > ( & mut self , name : impl ToString , function : F )
494
+ fn add_field_function_set < F , A > ( & mut self , name : impl Into < StdString > , function : F )
488
495
where
489
496
F : FnMut ( & Lua , AnyUserData , A ) -> Result < ( ) > + MaybeSend + ' static ,
490
497
A : FromLua ;
@@ -497,7 +504,7 @@ pub trait UserDataFields<T> {
497
504
///
498
505
/// `mlua` will trigger an error on an attempt to define a protected metamethod,
499
506
/// like `__gc` or `__metatable`.
500
- fn add_meta_field < V > ( & mut self , name : impl ToString , value : V )
507
+ fn add_meta_field < V > ( & mut self , name : impl Into < StdString > , value : V )
501
508
where
502
509
V : IntoLua + ' static ;
503
510
@@ -509,7 +516,7 @@ pub trait UserDataFields<T> {
509
516
///
510
517
/// `mlua` will trigger an error on an attempt to define a protected metamethod,
511
518
/// like `__gc` or `__metatable`.
512
- fn add_meta_field_with < F , R > ( & mut self , name : impl ToString , f : F )
519
+ fn add_meta_field_with < F , R > ( & mut self , name : impl Into < StdString > , f : F )
513
520
where
514
521
F : FnOnce ( & Lua ) -> Result < R > + ' static ,
515
522
R : IntoLua ;
0 commit comments