Expand description
fs4
Extended utilities for working with files and filesystems in Rust.
This is a fork of the fs2-rs crate, the aim for this fork is to support async
and replace libc by rustix.
§Installation
-
std
[dependencies] fs4 = { version = "1", features = ["sync"] } -
[dependencies] fs4 = { version = "1", features = ["async-std"] } -
[dependencies] fs4 = { version = "1", features = ["fs-err2"] } -
[dependencies] fs4 = { version = "1", features = ["fs-err2-tokio"] } -
[dependencies] fs4 = { version = "1", features = ["fs-err3"] } -
[dependencies] fs4 = { version = "1", features = ["fs-err3-tokio"] } -
[dependencies] fs4 = { version = "1", features = ["smol"] } -
[dependencies] fs4 = { version = "1", features = ["tokio"] }
§Features
- file locks.
- file (pre)allocation.
- file allocation information.
- filesystem space usage information.
- async-std support
- fs-err
- smol support
- tokio support
§Minimum Supported Rust Version
fs4 itself compiles on Rust 1.75.0 (the value of rust-version in
Cargo.toml), and that guarantee covers the default sync feature.
Some opt-in features inherit a higher MSRV from their transitive
dependencies — enabling them requires whatever toolchain those crates
ask for, not what fs4 declares:
| Feature | Effective MSRV | Reason |
|---|---|---|
async-std | 1.85 | async-std pulls async-lock >= 3.4.2 (rust-version = 1.85) |
smol | 1.85 | smol pulls async-signal >= 0.2.14 (rust-version = 1.85) |
These bounds are set by upstream and can drift with future minor releases; pin the relevant dependency if you need an older toolchain.
§Platform Notes
§Fuchsia
Every feature builds on Fuchsia except fs-err3 and
fs-err3-tokio. The blocker is upstream: fs-err v3.3.0 calls
std::os::unix::fs::chroot, which rustc gates out on
target_os = "fuchsia". The fs4 Unix modules themselves compile
on Fuchsia (sync, fs-err2, async-std, smol, tokio all
work). Tracking issue: https://github.com/andrewhickman/fs-err/issues/90.
§License
fs4 is primarily distributed under the terms of both the MIT license and the
Apache License (Version 2.0).
See LICENSE-APACHE, LICENSE-MIT for details.
Copyright (c) 2026 Al Liu.
Copyright (c) 2015 Dan Burkert.
Modules§
- async_
std async-std - fs_err2
fs-err2 - fs_err3
fs-err3 - fs_
err2_ tokio fs-err2-tokio - fs_
err3_ tokio fs-err3-tokio - smol
smol - tokio
tokio
Structs§
- FsStats
FsStatscontains some common stats about a file system.
Enums§
- TryLock
Error - The error returned from
FileExt::try_lockandFileExt::try_lock_shared.
Traits§
- Async
File Ext - Extension trait for file which provides allocation and locking methods.
- DynAsync
File Ext - Object-safe variant of
AsyncFileExtreturning boxedSendfutures, so it can be used behind a trait object (e.g.Box<dyn DynAsyncFileExt>or&dyn DynAsyncFileExt). - FileExt
- Extension trait for file which provides allocation and locking methods.
Functions§
- allocation_
granularity Unix or Windows - Returns the filesystem’s disk space allocation granularity in bytes. The provided path may be for any file in the filesystem.
- available_
space Unix or Windows - Returns the available space in bytes to non-privileged users in the file system containing the provided path.
- free_
space Unix or Windows - Returns the number of free bytes in the file system containing the provided path.
- statvfs
Unix or Windows - Get the stats of the file system containing the provided path.
- total_
space Unix or Windows - Returns the total space in bytes in the file system containing the provided path.
Type Aliases§
- BoxFuture
- A heap-allocated, dynamically-typed
Sendfuture used byDynAsyncFileExtto keep its methods object-safe.