@@ -2150,17 +2150,25 @@ fn ensure_libclang_is_loaded() {}
2150
2150
#[ derive( Debug ) ]
2151
2151
#[ non_exhaustive]
2152
2152
pub enum BindgenError {
2153
- /// Any provided header was invalid.
2154
- InvalidHeader ( String ) ,
2153
+ /// The header was a folder.
2154
+ FolderAsHeader ( String ) ,
2155
+ /// Permissions to read the header is insufficient.
2156
+ InsufficientPermissions ( String ) ,
2157
+ /// The header does not exist.
2158
+ NotExist ( String ) ,
2155
2159
/// Clang diagnosed an error.
2156
2160
ClangDiagnostic ( String ) ,
2157
2161
}
2158
2162
2159
2163
impl std:: fmt:: Display for BindgenError {
2160
2164
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
2161
2165
match self {
2162
- BindgenError :: InvalidHeader ( message) => {
2163
- write ! ( f, "invalid header: {}" , message)
2166
+ BindgenError :: FolderAsHeader ( h) => write ! ( f, "'{}' is a folder" , h) ,
2167
+ BindgenError :: InsufficientPermissions ( h) => {
2168
+ write ! ( f, "insufficient permissions to read '{}'" , h)
2169
+ }
2170
+ BindgenError :: NotExist ( h) => {
2171
+ write ! ( f, "header '{}' does not exist." , h)
2164
2172
}
2165
2173
BindgenError :: ClangDiagnostic ( message) => {
2166
2174
write ! ( f, "clang diagnosed error: {}" , message)
@@ -2347,23 +2355,16 @@ impl Bindings {
2347
2355
if let Some ( h) = options. input_header . as_ref ( ) {
2348
2356
if let Ok ( md) = std:: fs:: metadata ( h) {
2349
2357
if md. is_dir ( ) {
2350
- return Err ( BindgenError :: InvalidHeader ( format ! (
2351
- "'{}' is a folder" ,
2352
- h
2353
- ) ) ) ;
2358
+ return Err ( BindgenError :: FolderAsHeader ( h. into ( ) ) ) ;
2354
2359
}
2355
2360
if !can_read ( & md. permissions ( ) ) {
2356
- return Err ( BindgenError :: InvalidHeader ( format ! (
2357
- "insufficient permissions to read '{}'" ,
2358
- h
2359
- ) ) ) ;
2361
+ return Err ( BindgenError :: InsufficientPermissions (
2362
+ h. into ( ) ,
2363
+ ) ) ;
2360
2364
}
2361
2365
options. clang_args . push ( h. clone ( ) )
2362
2366
} else {
2363
- return Err ( BindgenError :: InvalidHeader ( format ! (
2364
- "header '{}' does not exist." ,
2365
- h
2366
- ) ) ) ;
2367
+ return Err ( BindgenError :: NotExist ( h. into ( ) ) ) ;
2367
2368
}
2368
2369
}
2369
2370
0 commit comments