@@ -15,6 +15,7 @@ use crate::state::{Lua, RawLua};
15
15
use crate :: string:: String ;
16
16
use crate :: table:: Table ;
17
17
use crate :: thread:: Thread ;
18
+ use crate :: traits:: ShortTypeName as _;
18
19
use crate :: types:: { LightUserData , MaybeSend , RegistryKey } ;
19
20
use crate :: userdata:: { AnyUserData , UserData } ;
20
21
use crate :: value:: { FromLua , IntoLua , Nil , Value } ;
@@ -72,7 +73,7 @@ impl FromLua for String {
72
73
lua. coerce_string ( value) ?
73
74
. ok_or_else ( || Error :: FromLuaConversionError {
74
75
from : ty,
75
- to : "string" ,
76
+ to : "string" . to_string ( ) ,
76
77
message : Some ( "expected string or number" . to_string ( ) ) ,
77
78
} )
78
79
}
@@ -116,7 +117,7 @@ impl FromLua for Table {
116
117
Value :: Table ( table) => Ok ( table) ,
117
118
_ => Err ( Error :: FromLuaConversionError {
118
119
from : value. type_name ( ) ,
119
- to : "table" ,
120
+ to : "table" . to_string ( ) ,
120
121
message : None ,
121
122
} ) ,
122
123
}
@@ -150,7 +151,7 @@ impl FromLua for Function {
150
151
Value :: Function ( table) => Ok ( table) ,
151
152
_ => Err ( Error :: FromLuaConversionError {
152
153
from : value. type_name ( ) ,
153
- to : "function" ,
154
+ to : "function" . to_string ( ) ,
154
155
message : None ,
155
156
} ) ,
156
157
}
@@ -184,7 +185,7 @@ impl FromLua for Thread {
184
185
Value :: Thread ( t) => Ok ( t) ,
185
186
_ => Err ( Error :: FromLuaConversionError {
186
187
from : value. type_name ( ) ,
187
- to : "thread" ,
188
+ to : "thread" . to_string ( ) ,
188
189
message : None ,
189
190
} ) ,
190
191
}
@@ -218,7 +219,7 @@ impl FromLua for AnyUserData {
218
219
Value :: UserData ( ud) => Ok ( ud) ,
219
220
_ => Err ( Error :: FromLuaConversionError {
220
221
from : value. type_name ( ) ,
221
- to : "userdata" ,
222
+ to : "userdata" . to_string ( ) ,
222
223
message : None ,
223
224
} ) ,
224
225
}
@@ -336,7 +337,7 @@ impl FromLua for LightUserData {
336
337
Value :: LightUserData ( ud) => Ok ( ud) ,
337
338
_ => Err ( Error :: FromLuaConversionError {
338
339
from : value. type_name ( ) ,
339
- to : "light userdata" ,
340
+ to : "lightuserdata" . to_string ( ) ,
340
341
message : None ,
341
342
} ) ,
342
343
}
@@ -359,7 +360,7 @@ impl FromLua for crate::types::Vector {
359
360
Value :: Vector ( v) => Ok ( v) ,
360
361
_ => Err ( Error :: FromLuaConversionError {
361
362
from : value. type_name ( ) ,
362
- to : "vector" ,
363
+ to : "vector" . to_string ( ) ,
363
364
message : None ,
364
365
} ) ,
365
366
}
@@ -386,7 +387,7 @@ impl FromLua for StdString {
386
387
. coerce_string ( value) ?
387
388
. ok_or_else ( || Error :: FromLuaConversionError {
388
389
from : ty,
389
- to : "String" ,
390
+ to : Self :: type_name ( ) ,
390
391
message : Some ( "expected string or number" . to_string ( ) ) ,
391
392
} ) ?
392
393
. to_str ( ) ?
@@ -405,7 +406,7 @@ impl FromLua for StdString {
405
406
. map ( |s| s. to_owned ( ) )
406
407
. map_err ( |e| Error :: FromLuaConversionError {
407
408
from : "string" ,
408
- to : "String" ,
409
+ to : Self :: type_name ( ) ,
409
410
message : Some ( e. to_string ( ) ) ,
410
411
} ) ;
411
412
}
@@ -448,7 +449,7 @@ impl FromLua for Box<str> {
448
449
. coerce_string ( value) ?
449
450
. ok_or_else ( || Error :: FromLuaConversionError {
450
451
from : ty,
451
- to : "Box<str>" ,
452
+ to : Self :: type_name ( ) ,
452
453
message : Some ( "expected string or number" . to_string ( ) ) ,
453
454
} ) ?
454
455
. to_str ( ) ?
@@ -472,15 +473,15 @@ impl FromLua for CString {
472
473
. coerce_string ( value) ?
473
474
. ok_or_else ( || Error :: FromLuaConversionError {
474
475
from : ty,
475
- to : "CString" ,
476
+ to : Self :: type_name ( ) ,
476
477
message : Some ( "expected string or number" . to_string ( ) ) ,
477
478
} ) ?;
478
479
479
480
match CStr :: from_bytes_with_nul ( & string. as_bytes_with_nul ( ) ) {
480
481
Ok ( s) => Ok ( s. into ( ) ) ,
481
482
Err ( _) => Err ( Error :: FromLuaConversionError {
482
483
from : ty,
483
- to : "CString" ,
484
+ to : Self :: type_name ( ) ,
484
485
message : Some ( "invalid C-style string" . to_string ( ) ) ,
485
486
} ) ,
486
487
}
@@ -525,7 +526,7 @@ impl FromLua for BString {
525
526
. coerce_string ( value) ?
526
527
. ok_or_else ( || Error :: FromLuaConversionError {
527
528
from : ty,
528
- to : "BString" ,
529
+ to : Self :: type_name ( ) ,
529
530
message : Some ( "expected string or number" . to_string ( ) ) ,
530
531
} ) ?
531
532
. as_bytes ( ) )
@@ -588,7 +589,7 @@ macro_rules! lua_convert_int {
588
589
. or_else( || cast( self ) . map( Value :: Number ) )
589
590
// This is impossible error because conversion to Number never fails
590
591
. ok_or_else( || Error :: ToLuaConversionError {
591
- from: stringify!( $x) ,
592
+ from: stringify!( $x) . to_string ( ) ,
592
593
to: "number" ,
593
594
message: Some ( "out of range" . to_owned( ) ) ,
594
595
} )
@@ -619,7 +620,7 @@ macro_rules! lua_convert_int {
619
620
lua. coerce_number( value) ?
620
621
. ok_or_else( || Error :: FromLuaConversionError {
621
622
from: ty,
622
- to: stringify!( $x) ,
623
+ to: stringify!( $x) . to_string ( ) ,
623
624
message: Some (
624
625
"expected number or string coercible to number" . to_string( ) ,
625
626
) ,
@@ -630,7 +631,7 @@ macro_rules! lua_convert_int {
630
631
} )
631
632
. ok_or_else( || Error :: FromLuaConversionError {
632
633
from: ty,
633
- to: stringify!( $x) ,
634
+ to: stringify!( $x) . to_string ( ) ,
634
635
message: Some ( "out of range" . to_owned( ) ) ,
635
636
} )
636
637
}
@@ -644,7 +645,7 @@ macro_rules! lua_convert_int {
644
645
if ok != 0 {
645
646
return cast( i) . ok_or_else( || Error :: FromLuaConversionError {
646
647
from: "integer" ,
647
- to: stringify!( $x) ,
648
+ to: stringify!( $x) . to_string ( ) ,
648
649
message: Some ( "out of range" . to_owned( ) ) ,
649
650
} ) ;
650
651
}
@@ -676,7 +677,7 @@ macro_rules! lua_convert_float {
676
677
fn into_lua( self , _: & Lua ) -> Result <Value > {
677
678
cast( self )
678
679
. ok_or_else( || Error :: ToLuaConversionError {
679
- from: stringify!( $x) ,
680
+ from: stringify!( $x) . to_string ( ) ,
680
681
to: "number" ,
681
682
message: Some ( "out of range" . to_string( ) ) ,
682
683
} )
@@ -691,13 +692,13 @@ macro_rules! lua_convert_float {
691
692
lua. coerce_number( value) ?
692
693
. ok_or_else( || Error :: FromLuaConversionError {
693
694
from: ty,
694
- to: stringify!( $x) ,
695
+ to: stringify!( $x) . to_string ( ) ,
695
696
message: Some ( "expected number or string coercible to number" . to_string( ) ) ,
696
697
} )
697
698
. and_then( |n| {
698
699
cast( n) . ok_or_else( || Error :: FromLuaConversionError {
699
700
from: ty,
700
- to: stringify!( $x) ,
701
+ to: stringify!( $x) . to_string ( ) ,
701
702
message: Some ( "number out of range" . to_string( ) ) ,
702
703
} )
703
704
} )
@@ -712,7 +713,7 @@ macro_rules! lua_convert_float {
712
713
if ok != 0 {
713
714
return cast( i) . ok_or_else( || Error :: FromLuaConversionError {
714
715
from: "number" ,
715
- to: stringify!( $x) ,
716
+ to: stringify!( $x) . to_string ( ) ,
716
717
message: Some ( "out of range" . to_owned( ) ) ,
717
718
} ) ;
718
719
}
@@ -771,13 +772,13 @@ where
771
772
vec. try_into ( )
772
773
. map_err ( |vec : Vec < T > | Error :: FromLuaConversionError {
773
774
from : "table" ,
774
- to : "Array" ,
775
- message : Some ( format ! ( "expected table of length {}, got {}" , N , vec. len( ) ) ) ,
775
+ to : Self :: type_name ( ) ,
776
+ message : Some ( format ! ( "expected table of length {N }, got {}" , vec. len( ) ) ) ,
776
777
} )
777
778
}
778
779
_ => Err ( Error :: FromLuaConversionError {
779
780
from : value. type_name ( ) ,
780
- to : "Array" ,
781
+ to : Self :: type_name ( ) ,
781
782
message : Some ( "expected table" . to_string ( ) ) ,
782
783
} ) ,
783
784
}
@@ -812,7 +813,7 @@ impl<T: FromLua> FromLua for Vec<T> {
812
813
Value :: Table ( table) => table. sequence_values ( ) . collect ( ) ,
813
814
_ => Err ( Error :: FromLuaConversionError {
814
815
from : value. type_name ( ) ,
815
- to : "Vec" ,
816
+ to : Self :: type_name ( ) ,
816
817
message : Some ( "expected table" . to_string ( ) ) ,
817
818
} ) ,
818
819
}
@@ -834,7 +835,7 @@ impl<K: Eq + Hash + FromLua, V: FromLua, S: BuildHasher + Default> FromLua for H
834
835
} else {
835
836
Err ( Error :: FromLuaConversionError {
836
837
from : value. type_name ( ) ,
837
- to : "HashMap" ,
838
+ to : Self :: type_name ( ) ,
838
839
message : Some ( "expected table" . to_string ( ) ) ,
839
840
} )
840
841
}
@@ -856,7 +857,7 @@ impl<K: Ord + FromLua, V: FromLua> FromLua for BTreeMap<K, V> {
856
857
} else {
857
858
Err ( Error :: FromLuaConversionError {
858
859
from : value. type_name ( ) ,
859
- to : "BTreeMap" ,
860
+ to : Self :: type_name ( ) ,
860
861
message : Some ( "expected table" . to_string ( ) ) ,
861
862
} )
862
863
}
@@ -880,7 +881,7 @@ impl<T: Eq + Hash + FromLua, S: BuildHasher + Default> FromLua for HashSet<T, S>
880
881
Value :: Table ( table) => table. pairs :: < T , Value > ( ) . map ( |res| res. map ( |( k, _) | k) ) . collect ( ) ,
881
882
_ => Err ( Error :: FromLuaConversionError {
882
883
from : value. type_name ( ) ,
883
- to : "HashSet" ,
884
+ to : Self :: type_name ( ) ,
884
885
message : Some ( "expected table" . to_string ( ) ) ,
885
886
} ) ,
886
887
}
@@ -904,7 +905,7 @@ impl<T: Ord + FromLua> FromLua for BTreeSet<T> {
904
905
Value :: Table ( table) => table. pairs :: < T , Value > ( ) . map ( |res| res. map ( |( k, _) | k) ) . collect ( ) ,
905
906
_ => Err ( Error :: FromLuaConversionError {
906
907
from : value. type_name ( ) ,
907
- to : "BTreeSet" ,
908
+ to : Self :: type_name ( ) ,
908
909
message : Some ( "expected table" . to_string ( ) ) ,
909
910
} ) ,
910
911
}
0 commit comments