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 { fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result11 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 DISCRIMINANT_OVERFLOW, 22 DOT_INCLUDE, 23 DOUBLE_UNDERSCORE, 24 RUST_TYPE_BY_VALUE, 25 UNSUPPORTED_TYPE, 26 USE_NOT_ALLOWED, 27 ]; 28 29 pub static BOX_CXX_TYPE: Error = Error { 30 msg: "Box of a C++ type is not supported yet", 31 label: None, 32 note: Some("hint: use UniquePtr<> or SharedPtr<>"), 33 }; 34 35 pub static CXXBRIDGE_RESERVED: Error = Error { 36 msg: "identifiers starting with cxxbridge are reserved", 37 label: Some("reserved identifier"), 38 note: Some("identifiers starting with cxxbridge are reserved"), 39 }; 40 41 pub static CXX_STRING_BY_VALUE: Error = Error { 42 msg: "C++ string by value is not supported", 43 label: None, 44 note: Some("hint: wrap it in a UniquePtr<>"), 45 }; 46 47 pub static CXX_TYPE_BY_VALUE: Error = Error { 48 msg: "C++ type by value is not supported", 49 label: None, 50 note: Some("hint: wrap it in a UniquePtr<> or SharedPtr<>"), 51 }; 52 53 pub static DISCRIMINANT_OVERFLOW: Error = Error { 54 msg: "discriminant overflow on value after ", 55 label: Some("discriminant overflow"), 56 note: Some("note: explicitly set `= 0` if that is desired outcome"), 57 }; 58 59 pub static DOT_INCLUDE: Error = Error { 60 msg: "#include relative to `.` or `..` is not supported in Cargo builds", 61 label: Some("#include relative to `.` or `..` is not supported in Cargo builds"), 62 note: Some("note: use a path starting with the crate name"), 63 }; 64 65 pub static DOUBLE_UNDERSCORE: Error = Error { 66 msg: "identifiers containing double underscore are reserved in C++", 67 label: Some("reserved identifier"), 68 note: Some("identifiers containing double underscore are reserved in C++"), 69 }; 70 71 pub static RUST_TYPE_BY_VALUE: Error = Error { 72 msg: "opaque Rust type by value is not supported", 73 label: None, 74 note: Some("hint: wrap it in a Box<>"), 75 }; 76 77 pub static UNSUPPORTED_TYPE: Error = Error { 78 msg: "unsupported type: ", 79 label: Some("unsupported type"), 80 note: None, 81 }; 82 83 pub static USE_NOT_ALLOWED: Error = Error { 84 msg: "`use` items are not allowed within cxx bridge", 85 label: Some("not allowed"), 86 note: Some( 87 "`use` items are not allowed within cxx bridge; only types defined\n\ 88 within your bridge, primitive types, or types exported by the cxx\n\ 89 crate may be used", 90 ), 91 }; 92