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