Skip to content

Commit e24afad

Browse files
MikuroXinaemilio
authored andcommitted
Change into PathBuf
1 parent 0d95ea1 commit e24afad

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/lib.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,24 +2151,26 @@ fn ensure_libclang_is_loaded() {}
21512151
#[non_exhaustive]
21522152
pub enum BindgenError {
21532153
/// The header was a folder.
2154-
FolderAsHeader(String),
2154+
FolderAsHeader(PathBuf),
21552155
/// Permissions to read the header is insufficient.
2156-
InsufficientPermissions(String),
2156+
InsufficientPermissions(PathBuf),
21572157
/// The header does not exist.
2158-
NotExist(String),
2158+
NotExist(PathBuf),
21592159
/// Clang diagnosed an error.
21602160
ClangDiagnostic(String),
21612161
}
21622162

21632163
impl std::fmt::Display for BindgenError {
21642164
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21652165
match self {
2166-
BindgenError::FolderAsHeader(h) => write!(f, "'{}' is a folder", h),
2166+
BindgenError::FolderAsHeader(h) => {
2167+
write!(f, "'{}' is a folder", h.display())
2168+
}
21672169
BindgenError::InsufficientPermissions(h) => {
2168-
write!(f, "insufficient permissions to read '{}'", h)
2170+
write!(f, "insufficient permissions to read '{}'", h.display())
21692171
}
21702172
BindgenError::NotExist(h) => {
2171-
write!(f, "header '{}' does not exist.", h)
2173+
write!(f, "header '{}' does not exist.", h.display())
21722174
}
21732175
BindgenError::ClangDiagnostic(message) => {
21742176
write!(f, "clang diagnosed error: {}", message)
@@ -2353,18 +2355,19 @@ impl Bindings {
23532355
}
23542356

23552357
if let Some(h) = options.input_header.as_ref() {
2356-
if let Ok(md) = std::fs::metadata(h) {
2358+
let path = Path::new(h);
2359+
if let Ok(md) = std::fs::metadata(path) {
23572360
if md.is_dir() {
2358-
return Err(BindgenError::FolderAsHeader(h.into()));
2361+
return Err(BindgenError::FolderAsHeader(path.into()));
23592362
}
23602363
if !can_read(&md.permissions()) {
23612364
return Err(BindgenError::InsufficientPermissions(
2362-
h.into(),
2365+
path.into(),
23632366
));
23642367
}
23652368
options.clang_args.push(h.clone())
23662369
} else {
2367-
return Err(BindgenError::NotExist(h.into()));
2370+
return Err(BindgenError::NotExist(path.into()));
23682371
}
23692372
}
23702373

0 commit comments

Comments
 (0)