Manipulate Unix file mode bits.
Every filesystem entry (or inode) on Unix has a bit field of mode bits that describe both the type of the file and its permissions.
These are classically displayed in the left of
ls output, and the permissions
can be changed with
chmod. For example:
assert_eq!(unix_mode::to_string(0o0040755), "drwxr-xr-x"); assert_eq!(unix_mode::to_string(0o0100640), "-rw-r-----");
The encoding is fairly standard across unices, and occurs in some file
formats and network protocols that might be seen on non-Unix platforms, including that of
This library isn’t Unix-specific and doesn’t depend on the underlying OS to interpret the bits.
For example, this can be used with the return value from std::os::unix::fs::MetadataExt::mode.
- Add Type enum for matching the file type.
- Add Access, and Accessor enums for testing permissions.
- More tests.
- Move changelog into Rustdoc.
- Fix tests on Windows.
- Initial release.
The different types of files known to this library
mode represents an allowed (
true) or denied (
Returns true if this mode represents a block device.
Returns true if this mode represents a character device.
Returns true if this mode represents a directory.
Returns true if this mode represents a fifo, also known as a named pipe.
Returns true if this mode represents a regular file.
Returns true if the set-group-ID bit is set
Returns true if the set-user-ID bit is set
Returns true if this mode represents a Unix-domain socket.
Returns true if the sticky bit is set
Returns true if this mode represents a symlink.
Convert Unix mode bits to a text string describing type and permissions,
as shown in