| 1 | //! Directory entry filtering. |
| 2 | |
| 3 | use once_cellrust-analyzer cargo once_cell 1.21.4 crate/::syncrust-analyzer cargo once_cell 1.21.4 sync/::Lazyrust-analyzer cargo once_cell 1.21.4 sync/Lazy#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 5 | collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#, |
| 6 | errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#, |
| 7 | fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#}, |
| 8 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::DirEntryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirEntry#, |
| 9 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, |
| 10 | pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, |
| 11 | }; |
| 12 | |
| 13 | /// Directories to exclude from the fix process. |
| 14 | pub static EXCLUDEDrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/EXCLUDED.: Lazyrust-analyzer cargo once_cell 1.21.4 sync/Lazy#<HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<&'static str>> = Lazyrust-analyzer cargo once_cell 1.21.4 sync/Lazy#::newrust-analyzer cargo once_cell 1.21.4 sync/impl#[`Lazy<T, F>`]new().(|| { |
| 15 | let mut excluded = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().(); |
| 16 | excluded.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(".git"); |
| 17 | excluded.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().("auto"); |
| 18 | excluded.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().("ci"); |
| 19 | excluded.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().("docs"); |
| 20 | excluded.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().("gir"); |
| 21 | excluded.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().("gir-files"); |
| 22 | excluded.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().("target"); |
| 23 | excluded.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().("sys"); |
| 24 | excluded |
| 25 | }); |
| 26 | |
| 27 | /// Checks the given directory entry. |
| 28 | #[inline] |
| 29 | pub fn checkrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/check().(entry: &DirEntryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirEntry#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<CheckOkrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#, CheckErrorrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#> { |
| 30 | let entry_type = entry |
| 31 | .file_typerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_type().() |
| 32 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| CheckErrorrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#::DirEntryrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#DirEntry#(entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().(), err))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 33 | |
| 34 | let entry_name = entry.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().(); |
| 35 | let entry_name = match entry_name.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().() { |
| 36 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(entry_name) => entry_name, |
| 37 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(CheckErrorrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#::Namerust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#Name#(entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().(), entry_name)), |
| 38 | }; |
| 39 | |
| 40 | if entry_type.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_file().() { |
| 41 | if entry_name.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".rs") { |
| 42 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CheckOkrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#::RustFilerust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#RustFile#); |
| 43 | } |
| 44 | } else if entry_type.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_dir().() { |
| 45 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().EXCLUDEDrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/EXCLUDED..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(entry_name) { |
| 46 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CheckOkrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#::Directoryrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#Directory#); |
| 47 | } |
| 48 | } else { |
| 49 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CheckOkrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#::SkipUnspecifiedrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#SkipUnspecified#); |
| 50 | } |
| 51 | |
| 52 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CheckOkrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#::Skiprust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#Skip#(entry_name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 53 | } |
| 54 | |
| 55 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 56 | pub enum CheckOkrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk# { |
| 57 | Directoryrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#Directory#, |
| 58 | RustFilerust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#RustFile#, |
| 59 | Skiprust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#Skip#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 60 | SkipUnspecifiedrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckOk#SkipUnspecified#, |
| 61 | } |
| 62 | |
| 63 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 64 | pub enum CheckErrorrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError# { |
| 65 | Namerust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#Name#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#), |
| 66 | DirEntryrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#DirEntry#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 67 | } |
| 68 | |
| 69 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for CheckErrorrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError# { |
| 70 | fn fmtrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/impl#[CheckError][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 71 | use CheckErrorrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#::*; |
| 72 | |
| 73 | match self { |
| 74 | Namerust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#Name#(path, name) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "error converting dir entry name {:?} {:?}", path, name), |
| 75 | DirEntryrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError#DirEntry#(path, err) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "error checking dir entry {:?}: {}", path, err), |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | impl Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for CheckErrorrust-analyzer cargo fix-getters-rules 0.3.2 dir_entry/CheckError# {} |