Skip to content

Commit b741271

Browse files
committed
TVMPODValue macro
1 parent 3441b95 commit b741271

File tree

6 files changed

+200
-296
lines changed

6 files changed

+200
-296
lines changed

rust/common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "tvm-common"
33
version = "0.1.0"
44
authors = ["TVM Contributors"]
55
license = "Apache-2.0"
6+
edition = "2018"
67

78
[features]
89
bindings = []

rust/common/src/errors.rs

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,11 @@
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+
)]
226
pub 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-
// }

rust/common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This crate contains the refactored basic components required
22
//! for `runtime` and `frontend` TVM crates.
33
4-
#![feature(box_syntax, trait_alias)]
4+
#![feature(box_syntax, type_alias_enum_variants, trait_alias)]
55

66
#[macro_use]
77
extern crate failure;

0 commit comments

Comments
 (0)