e_crate_version_checker/
lib.rs

1//! Library for `e_crate_version_checker`.
2//!
3//! Provides functionality to query crates.io for crate version information.
4
5pub const LIB_VERSION: &str = env!("CARGO_PKG_VERSION");
6
7pub mod e_crate_update;
8pub mod e_interactive_crate_upgrade;
9
10// Create a prelude module that re-exports key items
11pub mod prelude {
12    pub use crate::e_crate_update::user_agent::{get_user_agent, set_user_agent_override};
13    pub use crate::e_crate_update::version::local_crate_version_via_executable;
14    pub use crate::e_crate_update::version::lookup_local_version_via_cargo;
15    pub use crate::e_crate_update::*;
16    pub use crate::e_interactive_crate_upgrade::*;
17    pub use crate::register_user_crate;
18    pub use crate::LIB_VERSION;
19}
20
21// // Tests for changelog parsing
22// #[cfg(all(test, feature = "changelog"))]
23// mod tests {
24//     use super::*;
25//     use parse_changelog::parse;
26//     #[test]
27//     fn test_changelog_contains_latest_section() {
28//         // FULL_CHANGELOG should be included at compile time
29//         let changelog = e_interactive_crate_upgrade::FULL_CHANGELOG;
30//         let parsed = parse(changelog).expect("Failed to parse FULL_CHANGELOG");
31//         // Expect a known version from the consumer's changelog
32//         let version = "0.2.14";
33//         assert!(
34//             parsed.get(version).is_some(),
35//             "Changelog should contain section for version {}",
36//             version
37//         );
38//         let notes = &parsed.get(version).unwrap().notes;
39//         // Check for a known substring from that section
40//         assert!(
41//             notes.contains("rust-script / scriptisto kind detection"),
42//             "Changelog notes for version {} should contain expected text",
43//             version
44//         );
45//     }
46// }
47
48/// A macro that registers the caller’s crate name in the user agent string.
49/// This macro captures the caller's crate name using `env!("CARGO_PKG_NAME")`.
50#[macro_export]
51macro_rules! register_user_crate {
52    () => {{
53        let ua = format!(
54            "e_crate_version_checker (https://crates.io/crates/e_crate_version_checker) v{} [used by {} v{}]",
55            $crate::LIB_VERSION,        // This always uses the library's version.
56            env!("CARGO_PKG_NAME"),        // This will still be the consumer's crate name.
57            env!("CARGO_PKG_VERSION")     // This will still be the consumer's crate version.
58        );
59        $crate::e_crate_update::user_agent::set_user_agent_override(ua);
60    }};
61}