1- use std:: fmt;
2-
3- static TYPE_CODE_STRS : [ & str ; 15 ] = [
4- "int" ,
5- "uint" ,
6- "float" ,
7- "handle" ,
8- "null" ,
9- "TVMType" ,
10- "TVMContext" ,
11- "ArrayHandle" ,
12- "NodeHandle" ,
13- "ModuleHandle" ,
14- "FuncHandle" ,
15- "str" ,
16- "bytes" ,
17- "NDArrayContainer" ,
18- "ExtBegin" ,
19- ] ;
20-
211#[ derive( Debug , Fail ) ]
2+ #[ fail(
3+ display = "Could not downcast `{}` into `{}`" ,
4+ expected_type, actual_type
5+ ) ]
226pub struct ValueDowncastError {
23- actual_type_code : i64 ,
24- expected_type_code : i64 ,
25- }
26-
27- impl ValueDowncastError {
28- pub fn new ( actual_type_code : i64 , expected_type_code : i64 ) -> Self {
29- Self {
30- actual_type_code,
31- expected_type_code,
32- }
33- }
34- }
35-
36- impl fmt:: Display for ValueDowncastError {
37- fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
38- write ! (
39- formatter,
40- "Could not downcast TVMValue: expected `{}` but was {}" ,
41- TYPE_CODE_STRS [ self . actual_type_code as usize ] ,
42- TYPE_CODE_STRS [ self . expected_type_code as usize ]
43- )
44- }
7+ pub actual_type : String ,
8+ pub expected_type : & ' static str ,
459}
4610
4711#[ derive( Debug , Fail ) ]
@@ -62,18 +26,3 @@ impl FuncCallError {
6226 }
6327 }
6428}
65-
66- // error_chain! {
67- // errors {
68- // TryFromTVMRetValueError(expected_type: String, actual_type_code: i64) {
69- // description("mismatched types while downcasting TVMRetValue")
70- // display("invalid downcast: expected `{}` but was `{}`",
71- // expected_type, type_code_to_string(actual_type_code))
72- // }
73- // }
74- // foreign_links {
75- // IntoString(std::ffi::IntoStringError);
76- // ParseInt(std::num::ParseIntError);
77- // Utf8(std::str::Utf8Error);
78- // }
79- // }
0 commit comments