rust_releases/lib.rs
1#![deny(missing_docs)]
2#![deny(clippy::all)]
3#![deny(unsafe_code)]
4
5//! This crate aims to provide an index of Rust releases, and make it available to Rust programs.
6//!
7//! # Introduction
8//!
9//! The Rust programming language uses deterministic versioning for toolchain releases. Stable versions use SemVer,
10//! while nightly, beta and historical builds can be accessed by using dated builds (YY-MM-DD).
11//!
12//! Unfortunately, a complete index of releases is not available any more. There are however
13//! a few places where we can find partial release indices, from which we can build our own
14//! index.
15//!
16//! This process consists of two parts: 1) obtaining the data sources, and 2) building the index
17//! from these data sources. For the first part `rust-releases` provides the [`FetchResources`] trait, and
18//! for the second part `rust-releases` provides the [`Source`] trait.
19//! Both traits find their origin in the `rust-releases-core` crate, and re-exported here.
20//!
21//! # Using `rust-releases`
22//!
23//! To use this library, you can either add `rust-releases-core` as a dependency, combined with any
24//! implemented source library, or you can add `rust-releases` as a dependency, and enable the
25//! implemented source libraries of your choice as [`features`].
26//!
27//! By default, all four sources are enabled when depending on `rust-releases`. You can disable these
28//! by setting `default-features = false` for `rust-releases` in the `Cargo.toml` manifest, or by
29//! calling cargo with `cargo --no-default-features`. You can then cherry pick sources by adding the `features`
30//! key to the `rust-releases` dependency and enabling the features you want, or by calling cargo with
31//! `cargo --features "rust-releases-rust-changelog,rust-releases-rust-dist"` or any other combination of features
32//! and sources.
33//!
34//! To use rust-releases, you must add at least one source implementation.
35//!
36//! **Example: using rust-releases-core + implemented source as dependency**
37//!
38//! To use `rust-releases-core` as a dependency, combined with any implemented source library; add
39//! the following to your `Cargo.toml`:
40//!
41//! ```toml
42//! # replace `*` with latest version, and
43//! # replace `$RUST_RELEASES_SOURCE` with one of the implemented source crates
44//! [dependencies]
45//! rust-releases-core = "*"
46//! rust-releases-$RUST_RELEASES_SOURCE
47//! ```
48//!
49//! For example:
50//!
51//! ```toml
52//! [dependencies]
53//! rust-releases-core = "0.15.0"
54//! rust-releases-rust-dist = "0.15.0"
55//! ```
56//!
57//!
58//! **Example using rust-releases + implemented source(s) as feature**
59//!
60//! To use `rust-releases` as a dependency, and enable the implemented source libraries of your choice
61//! as [`features`], add the following to your `Cargo.toml`:
62//!
63//! ```toml
64//! # replace `*` with latest version, and replace `$RUST_RELEASES_SOURCE` with one of the available source implementations
65//! [dependencies.rust-releases]
66//! version = "*"
67//! default-features = false
68//! features = ["rust-release-$RUST_RELEASES_SOURCE"]
69//! ```
70//!
71//! For example:
72//!
73//! ```toml
74//! [dependencies.rust-releases]
75//! version = "0.15.0"
76//! default-features = false
77//! features = ["rust-release-rust-dist"]
78//! ```
79//!
80//! # Implemented sources
81//!
82//! `rust-releases` provides four [`Source`] implementations. Three out of four also provide
83//! a [`FetchResources`] implementation. Each implementation requires adding the implementation crate
84//! as an additional dependency or feature (see <a href="#using-rust-releases">using rust-releases</a>.
85//!
86//! The implementations are:
87//! 1) [`RustChangelog`]: Build an index from the [RELEASES.md](https://raw.githubusercontent.com/rust-lang/rust/master/RELEASES.md) found in the root of the Rust source code repository.
88//! * Select this implementation by adding `rust-releases-rust-changelog` as a dependency
89//! 2) [`RustDist`]: Build an index from the AWS S3 Rust distribution bucket; input data can be obtained using the [`FetchResources`] trait.
90//! * Select this implementation by adding `rust-releases-rust-dist` as a dependency
91//!
92//! # Choosing an implementation
93//!
94//! When in doubt, use the [`RustChangelog`] source for stable releases, and [`RustDist`] for anything else.
95//!
96//! In the below example, we'll use one of the above sources ([`RustChangelog`]) to show you how you can
97//! use this library.
98//!
99//! # Example
100//!
101//! ```rust,no_run
102//! use rust_releases_core::{FetchResources, Source, Channel, ReleaseIndex};
103//! use rust_releases_rust_changelog::RustChangelog;
104//!
105//! // We choose the RustChangelog source for this example; alternatives are RustDistWithCLI and ChannelManifests
106//! let source = RustChangelog::fetch_channel(Channel::Stable).unwrap();
107//!
108//! // Build a release index using our source of choice
109//! let index = ReleaseIndex::from_source(source).unwrap();
110//!
111//! // Do something with the release information
112//! index.releases()
113//! .iter()
114//! .for_each(|release| {
115//! println!("release {:?}", release)
116//! });
117//!
118//! ```
119//! # Table of implemented features
120//!
121//! <table>
122//! <thead>
123//! <tr>
124//! <th>Type of data source</th>
125//! <th>Crate</th>
126//! <th>Trait</th>
127//! <th>Implemented</th>
128//! <th>Channels<sup>1</sup></th>
129//! <th>Speed<sup>2, 3</sup></th>
130//! <th>On disk cache size<sup>4</sup></th>
131//! <th>Notes</th>
132//! </tr>
133//! </thead>
134//! <tbody>
135//! <tr>
136//! <td rowspan="2">RustChangelog</td>
137//! <td rowspan="2"><code>rust-releases-rust-changelog</code></td>
138//! <td>Source</td>
139//! <td>✅</td>
140//! <td rowspan="2">Stable</td>
141//! <td>Fast</td>
142//! <td>-</td>
143//! <td rowspan="2"></td>
144//! </tr>
145//! <tr>
146//! <td>FetchResources</td>
147//! <td>✅</td>
148//! <td>Instant (<1 second)</td>
149//! <td>~491 KB</td>
150//! </tr>
151//! <tr>
152//! <td rowspan="2">RustDist</td>
153//! <td rowspan="2"><code>rust-releases-rust-dist</code></td>
154//! <td>Source</td>
155//! <td>✅</td>
156//! <td rowspan="2">Stable, <strike>Beta & Nightly</strike><sup>To be implemented</sup></td>
157//! <td>Fast</td>
158//! <td>-</td>
159//! <td rowspan="2"></td>
160//! </tr>
161//! <tr>
162//! <td>FetchResources</td>
163//! <td>✅</td>
164//! <td>Medium fast (~20 seconds)</td>
165//! <td>~1 MB</td>
166//! </tr>
167//! </tbody>
168//! </table>
169//!
170//! <sup>1</sup>: Currently most of the `rust-releases` public API supports only stable. Support for the beta and nightly channel is work-in-progress, and the table currently lists whether there is theoretical support for these channels.<br>
171//! <sup>2</sup>: Speed for the `Source` trait primarily consist of parsing speed<br>
172//! <sup>3</sup>: Speed for the `FetchResources` trait is primarily limited by your own download speed, and the rate limiting of the server from which the resources are fetched<br>
173//! <sup>4</sup>: Approximate as of 2021-03-03 <br>
174//!
175//!
176//! # Issues
177//!
178//! Feel free to open an issue at our [repository](https://github.com/foresterre/rust-releases/issues)
179//! for questions, feature requests, bug fixes, or other points of feedback 🤗.
180//!
181//! [`FetchResources`]: rust_releases_core::FetchResources
182//! [`Source`]: rust_releases_core::Source
183//! [`RustChangelog`]: rust_releases_rust_changelog::RustChangelog
184//! [`RustDist`]: rust_releases_rust_dist::RustDist
185//! [`features`]: https://doc.rust-lang.org/cargo/reference/features.html#features
186
187/// Provides an iterator over the latest patch versions for stable releases.
188pub mod linear;
189
190// core re-exports
191pub use rust_releases_core::{
192 semver, Channel, CoreError, CoreResult, FetchResources, Release, ReleaseIndex, Source,
193};
194
195#[cfg(feature = "rust-releases-io")]
196pub use rust_releases_io::{
197 base_cache_dir, is_stale, BaseCacheDirError, CachedClient, CachedClientError, Document,
198 IsStaleError, RetrievedDocument, RustReleasesClient,
199};
200
201#[cfg(feature = "rust-releases-rust-changelog")]
202pub use rust_releases_rust_changelog::{RustChangelog, RustChangelogError, RustChangelogResult};
203
204#[cfg(feature = "rust-releases-rust-dist")]
205pub use rust_releases_rust_dist::{RustDist, RustDistError, RustDistResult};