1 use std::error; 2 use std::fmt; 3 4 /// Errors that can occur during code generation. 5 #[derive(Clone, Debug, PartialEq, Eq)] 6 pub enum Error { 7 /// Tried to generate an opaque blob for a type that did not have a layout. 8 NoLayoutForOpaqueBlob, 9 10 /// Tried to instantiate an opaque template definition, or a template 11 /// definition that is too difficult for us to understand (like a partial 12 /// template specialization). 13 InstantiationOfOpaqueType, 14 } 15 16 impl fmt::Display for Error { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 18 write!(f, "{}", error::Error::description(self)) 19 } 20 } 21 22 impl error::Error for Error { cause(&self) -> Option<&dyn error::Error>23 fn cause(&self) -> Option<&dyn error::Error> { 24 None 25 } 26 description(&self) -> &'static str27 fn description(&self) -> &'static str { 28 match *self { 29 Error::NoLayoutForOpaqueBlob => { 30 "Tried to generate an opaque blob, but had no layout" 31 } 32 Error::InstantiationOfOpaqueType => { 33 "Instantiation of opaque template type or partial template \ 34 specialization" 35 } 36 } 37 } 38 } 39 40 /// A `Result` of `T` or an error of `bindgen::codegen::error::Error`. 41 pub type Result<T> = ::std::result::Result<T, Error>; 42