Skip to main content

nik_rev/
lib.rs

1use std::env;
2
3pub fn export_env_vars_for_docs() {
4    let repo_name = env::var("CARGO_PKG_REPOSITORY").unwrap();
5    let repo_name = repo_name.strip_prefix("https://github.com/").unwrap();
6    let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
7    let msrv = env::var("CARGO_PKG_RUST_VERSION").unwrap_or_else(|_| "nightly".to_string());
8
9    let badges = format!(
10            "[![crates.io](https://img.shields.io/crates/v/{pkg_name}?style=flat-square&logo=rust)](https://crates.io/crates/{pkg_name})
11[![docs.rs](https://img.shields.io/docsrs/{pkg_name}?style=flat-square&logo=docs.rs)](https://docs.rs/{pkg_name})
12![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)
13![msrv](https://img.shields.io/badge/msrv-{msrv}-blue?style=flat-square&logo=rust)
14[![github](https://img.shields.io/github/stars/nik-rev/{repo_name})](https://github.com/nik-rev/{repo_name})"
15        );
16
17    let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
18    let major = env::var("CARGO_PKG_VERSION_MAJOR").unwrap();
19    let minor = env::var("CARGO_PKG_VERSION_MINOR").unwrap();
20
21    let add_dep = format!("```toml\n{pkg_name} = \"{major}.{minor}\"\n```\n");
22
23    println!("cargo:rustc-env=GENERATED_BADGES={}", badges);
24    println!("cargo:rustc-env=GENERATED_ADD_DEP={}", add_dep);
25}