rs_histver/constants.rs
1//! Centralized constants for the `rs-histver` project.
2//!
3//! All channel names, default configuration values, URL endpoints, and magic
4//! numbers are defined here. Import via `use crate::constants::*;` for
5//! convenience, or reference individually.
6
7// ── Channel name constants ──────────────────────────────────────────────
8
9/// Stable release channel identifier.
10pub const CHANNEL_STABLE: &str = "stable";
11/// Beta release channel identifier.
12pub const CHANNEL_BETA: &str = "beta";
13/// Nightly release channel identifier.
14pub const CHANNEL_NIGHTLY: &str = "nightly";
15
16/// All three valid channel names, ordered for iteration.
17pub const ALL_CHANNELS: &[&str] = &[CHANNEL_STABLE, CHANNEL_BETA, CHANNEL_NIGHTLY];
18
19// ── Default configuration values ────────────────────────────────────────
20
21/// Default number of days to probe for beta/nightly history.
22pub const DEFAULT_PROBE_DAYS: u32 = 30;
23
24/// Default HTTP request timeout (seconds).
25/// Increased from 15s to 60s for better compatibility with slow network connections
26/// (e.g., accessing GitHub from regions like China mainland).
27pub const DEFAULT_TIMEOUT_SECS: u64 = 60;
28
29/// Default maximum number of concurrent HTTP requests.
30pub const DEFAULT_MAX_CONCURRENCY: usize = 10;
31
32// ── GitHub API constants ────────────────────────────────────────────────
33
34/// Results per page for the GitHub Releases API.
35pub const GITHUB_PER_PAGE: u32 = 100;
36
37/// Maximum number of pages to fetch from GitHub Releases API
38/// (1500 releases — ~10 years of Rust history).
39pub const GITHUB_MAX_PAGES: u32 = 15;
40
41// ── Remote data source URLs ─────────────────────────────────────────────
42
43/// GitHub Releases API endpoint for the Rust language repository.
44pub const GITHUB_RELEASES_API: &str = "https://api.github.com/repos/rust-lang/rust/releases";
45
46/// Raw RELEASES.md for full historical stable release data.
47pub const RELEASES_MD_URL: &str =
48 "https://raw.githubusercontent.com/rust-lang/rust/master/RELEASES.md";
49
50/// Base URL for static.rust-lang.org distribution files.
51pub const STATIC_DIST_BASE_URL: &str = "https://static.rust-lang.org/dist";
52
53// ── Package identity ────────────────────────────────────────────────────
54
55/// Package / binary name, used for CLI identity and User-Agent prefix.
56pub const PKG_NAME: &str = env!("CARGO_PKG_NAME");
57
58/// Generate the default `User-Agent` header string, e.g. `"rs-histver/0.4.0"`.
59#[must_use]
60pub fn default_user_agent() -> String {
61 format!("{PKG_NAME}/{}", env!("CARGO_PKG_VERSION"))
62}