{"id":17158060,"url":"https://github.com/marcospb19/file_type_enum","last_synced_at":"2025-04-13T13:30:31.528Z","repository":{"id":57629324,"uuid":"295037312","full_name":"marcospb19/file_type_enum","owner":"marcospb19","description":"Small crate to ask for file types.","archived":false,"fork":false,"pushed_at":"2023-10-03T19:40:01.000Z","size":47,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T00:38:59.278Z","etag":null,"topics":["crates","filesystem","library","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcospb19.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-12T22:34:41.000Z","updated_at":"2023-03-08T14:27:43.000Z","dependencies_parsed_at":"2022-09-26T20:11:03.857Z","dependency_job_id":null,"html_url":"https://github.com/marcospb19/file_type_enum","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcospb19%2Ffile_type_enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcospb19%2Ffile_type_enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcospb19%2Ffile_type_enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcospb19%2Ffile_type_enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcospb19","download_url":"https://codeload.github.com/marcospb19/file_type_enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248720908,"owners_count":21151008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crates","filesystem","library","rust"],"created_at":"2024-10-14T22:10:29.370Z","updated_at":"2025-04-13T13:30:31.492Z","avatar_url":"https://github.com/marcospb19.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# file_type_enum\n\nAn enum with a variant for each file type.\n\n```rust\npub enum FileType {\n    Regular,\n    Directory,\n    Symlink,\n    BlockDevice, // unix only\n    CharDevice,  // unix only\n    Fifo,        // unix only\n    Socket,      // unix only\n}\n```\n\n## Alternatives:\n\n1. If you want a enum tree, check the crate [`fs-tree`](https://docs.rs/fs-tree).\n2. If you don't need an enum, check these methods from `std` instead:\n    - [`Path::is_file`](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_file).\n    - [`Path::is_dir`](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_dir).\n    - [`Path::is_symlink`](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_symlink).\n\n## Example:\n\n```rust\nuse std::{fs, io, path::Path};\n\nuse file_type_enum::FileType;\n\nfn move_file(from: \u0026Path, to: \u0026Path) -\u003e io::Result\u003c()\u003e {\n    let from_type = FileType::symlink_read_at(from)?;\n    let to_type = FileType::symlink_read_at(to)?;\n\n    use FileType::{Directory, Regular, Symlink};\n\n    match (from_type, to_type) {\n        (Directory, Directory) =\u003e {\n            println!(\"Replacing directory {to:?} by directory {from:?}.\");\n        }\n        (Regular, Regular) | (Symlink, Symlink) =\u003e {\n            // Might print:\n            //       \"Overwriting regular file at PATH.\"\n            //       \"Overwriting symbolic link at PATH.\"\n            println!(\"Overwriting {from_type} at {to:?} by {to:?}.\");\n        }\n        (_, Directory) =\u003e {\n            println!(\"Moving file at {from:?} into folder {to:?}.\");\n            fs::rename(from, to)?;\n        }\n        (_, _) =\u003e {\n            // Might print:\n            // -   \"Cannot overwrite regular file  with a symbolic link.\"\n            // -   \"Cannot overwrite directory     with a symbolic link.\"\n            // -   \"Cannot overwrite symbolic link with a regular file.\"\n            panic!(\"Cannot overwrite {to_type}     with a {from_type}.\");\n        }\n    }\n\n    Ok(())\n}\n```\n\nAs shown in the example `FileType` also implements `Display`.\n\n## Warning\n\nNote that, like `std` functions, [`FileType::read_at`] follows symlinks, therefore it is\nimpossible to get the [`FileType::Symlink`] variant. If you want symlink-awareness, use\n[`FileType::symlink_read_at`] instead.\n\n## Conversions\n\n- From [`AsRef\u003cPath\u003e`], [`fs::Metadata`] and [std's `FileType`].\n- From and into [`libc::mode_t`] (via the feature `\"mode-t-conversion\"`).\n\n[`AsRef\u003cPath\u003e`]: https://doc.rust-lang.org/std/path/struct.Path.html\n[`FileType::read_at`]: https://docs.rs/file_type_enum/latest/file_type_enum/enum.FileType.html#method.read_at\n[`FileType::symlink_read_at`]: https://docs.rs/file_type_enum/latest/file_type_enum/enum.FileType.html#method.symlink_read_at\n[`fs::Metadata`]: https://doc.rust-lang.org/std/fs/struct.Metadata.html\n[`libc::mode_t`]: https://docs.rs/libc/latest/libc/type.mode_t.html\n[std's `FileType`]: https://doc.rust-lang.org/std/fs/struct.FileType.html\n[`FileType::Symlink`]: https://docs.rs/file_type_enum/latest/file_type_enum/enum.FileType.html#variant.Symlink\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcospb19%2Ffile_type_enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcospb19%2Ffile_type_enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcospb19%2Ffile_type_enum/lists"}