rustc_version_const/lib.rs
1// SPDX-License-Identifier: 0BSD
2// rustc-version-const
3// Copyright (C) 2025 by LoRd_MuldeR <mulder2@gmx.de>
4
5#![no_std]
6#![allow(clippy::needless_doctest_main)]
7
8//! # rustc-version-const
9//!
10//! Makes the current **rustc** version available via a `const fn` at runtime.
11//!
12//! The version detection happens automatically at build-time.
13//!
14//! ### Usage
15//!
16//! Here is a simple example that demonstrates how to use `rustc_version()` in your code:
17//!
18//! ```rust
19//! use rustc_version_const::{rustc_version, rustc_version_full};
20//!
21//! const RUSTC_VERSION: &str = rustc_version();
22//!
23//! fn main() {
24//! println!("rustc version: \"{}\"", RUSTC_VERSION);
25//! }
26//! ```
27
28/// Returns the `rustc` version that was used to build this application
29///
30/// This function returns just the plain version number *without* revision, e.g., `1.90.0`.
31pub const fn rustc_version() -> &'static str {
32 static RUSTC_VERSION: &str = env!("_RUSTC_VERSION_CONST");
33 RUSTC_VERSION
34}
35
36/// Returns the `rustc` version that was used to build this application
37///
38/// This function returns the full version string, e.g., `rustc 1.90.0 (1159e78c4 2025-09-14)`.
39pub const fn rustc_version_full() -> &'static str {
40 static RUSTC_VERSION_FULL: &str = env!("_RUSTC_VERSION_CONST_FULL");
41 RUSTC_VERSION_FULL
42}