1use std::error;
2use std::fmt;
3
4#[derive(Clone, Debug, PartialEq, Eq)]
6pub(crate) enum Error {
7 NoLayoutForOpaqueBlob,
9
10 InstantiationOfOpaqueType,
14
15 UnsupportedAbi(&'static str),
17
18 InvalidPointerSize {
20 ty_name: String,
21 ty_size: usize,
22 ptr_size: usize,
23 },
24}
25
26impl fmt::Display for Error {
27 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28 match self {
29 Error::NoLayoutForOpaqueBlob => {
30 "Tried to generate an opaque blob, but had no layout.".fmt(f)
31 }
32 Error::InstantiationOfOpaqueType => {
33 "Instantiation of opaque template type or partial template specialization."
34 .fmt(f)
35 }
36 Error::UnsupportedAbi(abi) => {
37 write!(
38 f,
39 "{abi} ABI is not supported by the configured Rust target."
40 )
41 }
42 Error::InvalidPointerSize { ty_name, ty_size, ptr_size } => {
43 write!(f, "The {ty_name} pointer type has size {ty_size} but the current target's pointer size is {ptr_size}.")
44 }
45 }
46 }
47}
48
49impl error::Error for Error {}
50
51pub(crate) type Result<T> = ::std::result::Result<T, Error>;