1use std::fmt::{self, Display};
2
3#[derive(Copy, Clone)]
4pub(crate) struct Error {
5 pub msg: &'static str,
6 #[allow(dead_code)] pub label: Option<&'static str>,
8 #[allow(dead_code)] pub note: Option<&'static str>,
10}
11
12impl Display for Error {
13 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
14 self.msg.fmt(formatter)
15 }
16}
17
18pub(crate) static ERRORS: &[Error] = &[
19 BOX_CXX_TYPE,
20 CXXBRIDGE_RESERVED,
21 CXX_STRING_BY_VALUE,
22 CXX_TYPE_BY_VALUE,
23 DISCRIMINANT_OVERFLOW,
24 DOT_INCLUDE,
25 DOUBLE_UNDERSCORE,
26 RESERVED_LIFETIME,
27 RUST_TYPE_BY_VALUE,
28 UNSUPPORTED_TYPE,
29 USE_NOT_ALLOWED,
30];
31
32pub(crate) static BOX_CXX_TYPE: Error = Error {
33 msg: "Box of a C++ type is not supported yet",
34 label: None,
35 note: Some("hint: use UniquePtr<> or SharedPtr<>"),
36};
37
38pub(crate) static CXXBRIDGE_RESERVED: Error = Error {
39 msg: "identifiers starting with cxxbridge are reserved",
40 label: Some("reserved identifier"),
41 note: Some("identifiers starting with cxxbridge are reserved"),
42};
43
44pub(crate) static CXX_STRING_BY_VALUE: Error = Error {
45 msg: "C++ string by value is not supported",
46 label: None,
47 note: Some("hint: wrap it in a UniquePtr<>"),
48};
49
50pub(crate) static CXX_TYPE_BY_VALUE: Error = Error {
51 msg: "C++ type by value is not supported",
52 label: None,
53 note: Some("hint: wrap it in a UniquePtr<> or SharedPtr<>"),
54};
55
56pub(crate) static DISCRIMINANT_OVERFLOW: Error = Error {
57 msg: "discriminant overflow on value after ",
58 label: Some("discriminant overflow"),
59 note: Some("note: explicitly set `= 0` if that is desired outcome"),
60};
61
62pub(crate) static DOT_INCLUDE: Error = Error {
63 msg: "#include relative to `.` or `..` is not supported in Cargo builds",
64 label: Some("#include relative to `.` or `..` is not supported in Cargo builds"),
65 note: Some("note: use a path starting with the crate name"),
66};
67
68pub(crate) static DOUBLE_UNDERSCORE: Error = Error {
69 msg: "identifiers containing double underscore are reserved in C++",
70 label: Some("reserved identifier"),
71 note: Some("identifiers containing double underscore are reserved in C++"),
72};
73
74pub(crate) static RESERVED_LIFETIME: Error = Error {
75 msg: "invalid lifetime parameter name: `'static`",
76 label: Some("'static is a reserved lifetime name"),
77 note: None,
78};
79
80pub(crate) static RUST_TYPE_BY_VALUE: Error = Error {
81 msg: "opaque Rust type by value is not supported",
82 label: None,
83 note: Some("hint: wrap it in a Box<>"),
84};
85
86pub(crate) static UNSUPPORTED_TYPE: Error = Error {
87 msg: "unsupported type: ",
88 label: Some("unsupported type"),
89 note: None,
90};
91
92pub(crate) static USE_NOT_ALLOWED: Error = Error {
93 msg: "`use` items are not allowed within cxx bridge",
94 label: Some("not allowed"),
95 note: Some(
96 "`use` items are not allowed within cxx bridge; only types defined\n\
97 within your bridge, primitive types, or types exported by the cxx\n\
98 crate may be used",
99 ),
100};