trash
A cross-platform Rust library for moving files and folders to the operating system's recycle bin or trash.
Repository Health
Technical Analysis
trash is a Rust library for sending files and folders to the operating system’s recycle bin, trash, or rubbish bin instead of permanently deleting them. It offers a simple API — delete for a single path and delete_all for many — so applications can remove files in a way users can recover.
The library works across Windows, macOS, and any FreeDesktop-compliant Linux environment, including GNOME, KDE, and XFCE, implementing each platform’s native trash semantics behind one consistent interface. On supported platforms it can also list, restore, and permanently purge trashed items.
What You Get
- A
deletefunction for trashing a single file or folder - A
delete_allfunction for trashing multiple paths at once - Cross-platform support for Windows, macOS, and FreeDesktop Linux desktops
- Optional listing, restoring, and purging of trashed items on supported platforms
- Native per-platform implementations behind one consistent Rust interface
Common Use Cases
- Giving CLI tools and file managers a recoverable delete instead of permanent removal
- Cleaning up generated or temporary files while keeping them retrievable by the user
- Implementing an undo-friendly delete action in desktop applications
- Safely removing user data where accidental permanent deletion would be costly
Under The Hood
Architecture - The crate splits a shared public API in src/lib.rs from three platform-specific backends selected at compile time: windows.rs for the Windows shell recycle bin, the macos/ module for macOS trash semantics, and freedesktop.rs implementing the FreeDesktop Trash specification used by GNOME, KDE, XFCE, and similar desktops. The top-level functions (delete, delete_all, and platform-gated listing/restore APIs) dispatch to whichever backend matches the target OS, so callers get one interface over three very different underlying mechanisms.
Tech Stack - Written in pure Rust, the library relies on OS integration crates per platform (Windows shell APIs, macOS system bindings, and FreeDesktop directory handling on Linux) and is distributed on crates.io as trash. CI runs on GitHub Actions across the supported operating systems.
Code Quality - The repository includes an in-crate test module (src/tests.rs) exercising delete and restore behavior, and its 35 releases and long history reflect a mature, established project, though recent development activity is comparatively low. Platform code is cleanly isolated so changes to one OS backend do not affect the others.
API Design - The public API is deliberately tiny and familiar: trash::delete(path) reads almost identically to a normal file removal, which makes adoption trivial. Batch deletion via delete_all, plus optional list/restore/purge operations, cover more advanced needs without complicating the common case, and docs.rs provides full reference coverage.