ib_update/lib.rs
1/*!
2A lightweight library for software update.
3
4Features:
5- Lightweight
6 - Based on [`nyquest`](https://github.com/bdbai/nyquest),
7 can use either platform-native HTTP client or `reqwest`.
8 - 333 KiB on `x86_64-pc-windows-msvc` with HTTPS update checking.
9- Supported update sources:
10 - GitHub Releases
11- [Semantic Versioning](https://semver.org) handling.
12 - Optional pre-release update.
13- Provide both sync/async APIs.
14- Optional support for retrying multiple servers under unstable networks.
15
16## Blocking API
17Use [`UpdateConfig::builder`](github::UpdateConfig::builder) and [`build_blocking`](github::UpdateConfigBuilder::build_blocking).
18Make sure an nyquest backend is registered before making requests:
19
20```no_run
21// cargo add ib-update --features blocking
22// cargo add nyquest-preset --features blocking
23fn main() {
24 nyquest_preset::register();
25
26 let info = ib_update::github::UpdateConfig::builder()
27 .owner("owner")
28 .repo("repo")
29 .current_version(env!("CARGO_PKG_VERSION"))
30 .build_blocking()
31 .check()
32 .expect("failed to check for updates");
33
34 if info.has_update() {
35 println!("New version {} is available!", info.latest().tag);
36 }
37}
38```
39
40## Async API
41Use [`UpdateConfig::builder`](github::UpdateConfig::builder) and [`build_async`](github::UpdateConfigBuilder::build_async).
42Make sure an nyquest backend is registered before making requests:
43
44```no_run
45// cargo add ib-update --features async
46// cargo add nyquest-preset --features blocking
47fn main() {
48 nyquest_preset::register();
49
50 futures::executor::block_on(async {
51 let info = ib_update::github::UpdateConfig::builder()
52 .owner("owner")
53 .repo("repo")
54 .current_version(env!("CARGO_PKG_VERSION"))
55 .build_async()
56 .check()
57 .await
58 .expect("failed to check for updates");
59
60 if info.has_update() {
61 println!("New version {} is available!", info.latest().tag);
62 }
63 });
64}
65```
66
67## Binary size
68The following `Cargo.toml` settings are recommended if small binary size is desired:
69```toml
70[profile.release]
71lto = "fat"
72codegen-units = 1
73
74strip = true
75```
76These can reduce the size by ~50 KiB on `x86_64-pc-windows-msvc`.
77
78## Crate features
79*/
80#![cfg_attr(docsrs, feature(doc_cfg))]
81#![cfg_attr(feature = "doc", doc = document_features::document_features!())]
82
83mod git;
84pub mod github;
85mod http;
86
87/// Re-export of the `semver` crate for users who want to construct or compare
88/// version strings independently.
89pub use semver;
90
91#[cfg(test)]
92mod tests {
93 /// auto-register
94 // #[allow(unused)]
95 // use nyquest_preset;
96
97 #[ctor::ctor(unsafe)]
98 fn auto_register() {
99 nyquest_preset::register();
100 }
101}