Crate binswap_github
source ·Expand description
Download and swap binaries from GitHub
Usage
binswap
uses the same infrastructure as
cargo-binstall
to
determine where the latest binaries are stored. binswap-github
is the
backend to do this for GitHub specifically. It uses the GitHub releases to
download binaries for a supported target, and then downloads them to a
specified location, or optionally swaps them with the currently executed
binary.
This is particularly useful if you distribute binaries outside of package managers or in environments where the users are not expected to have Rust nor installed. With crate, you can bundle the updating mechanism into the distributed binary.
Example
The following example downloads the latest release ripgrep
from
GitHub, and swaps it with
the currently executed binary. .dry_run(true)
is added here to simulate
the execution, but not perform the update.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
binswap_github::builder()
.repo_author("BurntSushi")
.repo_name("ripgrep")
.asset_name("ripgrep")
.bin_name("rg")
.dry_run(true)
.build()?
.fetch_and_write_in_place_of_current_exec()
.await?;
Ok(())
}
The following does the same, but just writes the resulting binary to a new file.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
binswap_github::builder()
.repo_author("BurntSushi")
.repo_name("ripgrep")
.asset_name("ripgrep")
.bin_name("rg")
.dry_run(true)
.build()?
.fetch_and_write_to("./rg")
.await?;
Ok(())
}
Structs
- The parameters used to fetch and install binaries
- Builder for
BinswapGithub
.
Enums
- Error type for BinswapGithubBuilder
Functions
- Create a new builder. Finish by calling
.build()