| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame^] | 1 | use std::fmt::{self, Display}; |
| 2 | |
| 3 | #[derive(Copy, Clone)] |
| 4 | pub struct Error { |
| 5 | pub msg: &'static str, |
| 6 | pub label: Option<&'static str>, |
| 7 | pub note: Option<&'static str>, |
| 8 | } |
| 9 | |
| 10 | impl Display for Error { |
| 11 | fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 12 | self.msg.fmt(formatter) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | pub static ERRORS: &[Error] = &[ |
| 17 | BOX_CXX_TYPE, |
| 18 | CXXBRIDGE_RESERVED, |
| 19 | CXX_STRING_BY_VALUE, |
| 20 | CXX_TYPE_BY_VALUE, |
| 21 | DOUBLE_UNDERSCORE, |
| 22 | RUST_TYPE_BY_VALUE, |
| 23 | USE_NOT_ALLOWED, |
| 24 | ]; |
| 25 | |
| 26 | pub static BOX_CXX_TYPE: Error = Error { |
| 27 | msg: "Box of a C++ type is not supported yet", |
| 28 | label: None, |
| 29 | note: Some("hint: use UniquePtr<>"), |
| 30 | }; |
| 31 | |
| 32 | pub static CXXBRIDGE_RESERVED: Error = Error { |
| 33 | msg: "identifiers starting with cxxbridge are reserved", |
| 34 | label: Some("reserved identifier"), |
| 35 | note: Some("identifiers starting with cxxbridge are reserved"), |
| 36 | }; |
| 37 | |
| 38 | pub static CXX_STRING_BY_VALUE: Error = Error { |
| 39 | msg: "C++ string by value is not supported", |
| 40 | label: None, |
| 41 | note: Some("hint: wrap it in a UniquePtr<>"), |
| 42 | }; |
| 43 | |
| 44 | pub static CXX_TYPE_BY_VALUE: Error = Error { |
| 45 | msg: "C++ type by value is not supported", |
| 46 | label: None, |
| 47 | note: Some("hint: wrap it in a Box<> or UniquePtr<>"), |
| 48 | }; |
| 49 | |
| 50 | pub static DOUBLE_UNDERSCORE: Error = Error { |
| 51 | msg: "identifiers containing double underscore are reserved in C++", |
| 52 | label: Some("reserved identifier"), |
| 53 | note: Some("identifiers containing double underscore are reserved in C++"), |
| 54 | }; |
| 55 | |
| 56 | pub static RUST_TYPE_BY_VALUE: Error = Error { |
| 57 | msg: "opaque Rust type by value is not supported", |
| 58 | label: None, |
| 59 | note: Some("hint: wrap it in a Box<>"), |
| 60 | }; |
| 61 | |
| 62 | pub static USE_NOT_ALLOWED: Error = Error { |
| 63 | msg: "`use` items are not allowed within cxx bridge", |
| 64 | label: Some("not allowed"), |
| 65 | note: Some( |
| 66 | "`use` items are not allowed within cxx bridge; only types defined\n\ |
| 67 | within your bridge, primitive types, or types exported by the cxx\n\ |
| 68 | crate may be used", |
| 69 | ), |
| 70 | }; |