swdir
Swiftly traverse and scan directories recursively. Sway ðŸª, swing 🎷 or swim 🪼 in directories.
Quick start
use Swdir;
Recurse option
use ;
Allowlist and denylist
use ;
GUI / lazy loading API — scan_dir
Alongside the high-level Swdir::walk() there is a low-level, single-directory
scan API aimed at GUI tree views (iced, egui, …) that expand one node at a
time. Use scan_dir when you want to stream a tree into the UI as the user
clicks, rather than pay the cost of a full traversal up front.
How it differs from walk()
Swdir::walk() |
scan_dir(path) |
|
|---|---|---|
| Scope | recursive, whole tree | one directory, direct children only |
| Filtering / sorting | hidden filter, extension allow/deny-list | none (raw listing) |
| Parallelism | internal rayon pool | single-threaded |
| Runtime deps | none (sync) | none (sync) |
| Return type | DirNode (tree) |
Result<Vec<DirEntry>, ScanError> |
| Error handling | best-effort, warnings to stderr | atomic — first I/O failure is returned |
| Intended caller | CLI, batch tools | GUI lazy-loading, file pickers |
walk() remains unchanged and is still the right call for full or filtered
traversal. scan_dir is purely additive.
Basic usage
use Path;
use ;
Each DirEntry is owned (Send + 'static) and caches its FileType, so
is_dir() / is_file() / is_symlink() answer without additional syscalls.
Empty directories return Ok(Vec::new()); permission denied, missing paths,
and "not a directory" all return Err(ScanError::Io { path, source }) with
both the offending path and the original std::io::Error preserved.
iced lazy tree example
scan_dir is deliberately synchronous. To keep the iced runtime responsive,
wrap the call in std::thread::spawn and drive it via Task::perform:
use PathBuf;
use Task;
use ;
#
No tokio, no async-std, no feature flag — the crate stays runtime-agnostic.