Skip to main content

rs_histver/
lib.rs

1//! # rs-histver
2//!
3//! A library for querying Rust historical release versions.
4//!
5//! Pure network fetch — no database, no file system, no side effects.
6//! The **CLI binary** (`rs-histver`) additionally provides terminal formatting.
7//!
8//! ## As a library
9//!
10//! ```ignore
11//! use rs_histver::{fetch_releases, FetchOptions};
12//!
13//! #[tokio::main]
14//! async fn main() -> anyhow::Result<()> {
15//!     let releases = fetch_releases("stable", FetchOptions::default()).await?;
16//!     for r in &releases {
17//!         println!("{} ({})", r.version, r.date);
18//!     }
19//!     Ok(())
20//! }
21//! ```
22
23mod constants;
24mod domain;
25mod options;
26
27#[cfg(feature = "cli")]
28pub mod app;
29#[cfg(feature = "cli")]
30pub mod cli;
31pub(crate) mod infra;
32
33pub use constants::*;
34pub use domain::RustRelease;
35pub use infra::fetcher::{create_fetcher, ReleaseFetcher};
36pub use options::{FetchOptions, NetworkConfig};
37
38use anyhow::Result;
39
40/// Fetch Rust release data for a given channel.
41///
42/// # Parameters
43///
44/// - `channel` — `"stable"`, `"beta"`, or `"nightly"`
45/// - `opts` — query configuration ([`FetchOptions`])
46///
47/// # Returns
48///
49/// `Vec<RustRelease>` sorted by date descending.
50///
51/// # Errors
52///
53/// Returns an error if the channel name is unknown or the remote request fails.
54///
55/// # Examples
56///
57/// ```ignore
58/// use rs_histver::{fetch_releases, FetchOptions};
59///
60/// // Default options — 15s timeout, 10 concurrent, GitHub API for stable
61/// let releases = fetch_releases("stable", FetchOptions::default()).await?;
62///
63/// // Full history from RELEASES.md
64/// let releases = fetch_releases("stable",
65///     FetchOptions::new().full_history(true)
66/// ).await?;
67///
68/// // Recent 7 days of nightly builds
69/// let releases = fetch_releases("nightly",
70///     FetchOptions::new().probe_days(7)
71/// ).await?;
72/// ```
73pub async fn fetch_releases(channel: &str, opts: FetchOptions) -> Result<Vec<RustRelease>> {
74    let network = NetworkConfig::from(&opts);
75    let fetcher = infra::fetcher::create_fetcher(channel, opts.full_history, opts.probe_days)?;
76    fetcher.fetch(&network).await
77}