#replace #uninstall #system #higher-level #self-update #self-uninstall

self-replace

Utility crate that allows executables to replace or uninstall themselves

12 stable releases

1.5.0 Sep 1, 2024
1.4.0 Jul 21, 2024
1.3.7 Sep 19, 2023
1.3.6 Aug 25, 2023
1.3.3 May 19, 2023

#24 in Math

Download history 18476/week @ 2024-08-01 16846/week @ 2024-08-08 18730/week @ 2024-08-15 21995/week @ 2024-08-22 25852/week @ 2024-08-29 27017/week @ 2024-09-05 23657/week @ 2024-09-12 24181/week @ 2024-09-19 26514/week @ 2024-09-26 27797/week @ 2024-10-03 24473/week @ 2024-10-10 25510/week @ 2024-10-17 27989/week @ 2024-10-24 25852/week @ 2024-10-31 37792/week @ 2024-11-07 43655/week @ 2024-11-14

140,163 downloads per month
Used in 76 crates (14 directly)

Apache-2.0

27KB
283 lines

Self-Replace: A Utility For Self Replacing Executables

Crates.io License rustc 1.63.0 Documentation

self-replace is a crate that allows binaries to replace themselves with newer versions or to uninstall themselves. On Unix systems this is a simple feat, but on Windows a few hacks are needed which is why this crate exists.

This is a useful operation when working with single-executable utilties that want to implement a form of self updating or self uninstallation.

For details about the implementation refer to the documentation.

If you are looking for some higher level update logic, have a look at self_update which uses self-replace under the hood but provides automatic updating from GitHub releases or other distribution channels. Note that self_update is maintained by other maintainers.

Uninstall

To uninstall a binary, use self_delete.

self_replace::self_delete()?;

Updating

To replace a binary for updating, use self_replace.

let new_binary = "/path/to/new/binary";
self_replace::self_replace(&new_binary)?;
std::fs::remove_file(&new_binary)?;

Dependencies

~2–11MB
~132K SLoC