file_type_enum
A enum with one variant for each file type.
Cross-platform, this crate is made of a single small lib.rs
with a very
simple enum implementation so that you don't have to rewrite
your own.
Enum [FileType
]:
Examples:
use FileType;
let path = "/tmp";
let file_type = from_path.unwrap;
println!;
// Outputs: "There's a directory at /tmp!"
Errors:
- If path does not exist, or
- Current user don't have permissions to read
fs::Metadata
frompath
.
For each variant, there is also a short hand method:
let ft = from;
if ft.is_regular
if ft.is_directory
if ft.is_symlink
if ft.is_block_device
if ft.is_char_device
if ft.is_fifo
if ft.is_socket
```rust
```rust
use FileType;
let path = ".git";
let file_type = from_path.unwrap;
if file_type.is_directory
If path
points to a symlink, from_path(path)
follows it, so the
returned type can never be a symlink.
To avoid this, use FileType::from_symlink_path
, this don't follow, and can
return a symlink.
use FileType;
let path = "/dev/stdout";
let file_type = from_symlink_path.unwrap;
println!;
// Outputs: "There's a symbolic link at /dev/stdout!"
Conversions
- From
std::fs::FileType
. - From and into
libc::mode_t
(enablemode-t-conversion
optional feature).
Future versions note:
Changes might occur on std
API for Windows
(related to symlinks), I
personally don't consider this part very stable.
Helping and contributing:
It's easy to contribute to this crate, here are some options:
- Share it to a friend.
- Help improve this README.md, even with little details.
- Open an issue or PR in the repository.
- Leave a star on GitHub.
- Use it!!!
TODO:
Add example on how to add the crate with the feature to the Cargo.toml.