Expand description
§BestBefore
A Rust procedural macro for managing code with expiration dates.
Technical debt and code deprecation are persistent challenges in software development. As systems evolve, certain implementations become obsolete, APIs change, and better patterns emerge. However, identifying and removing deprecated code is often neglected, leading to maintenance burdens and unexpected bugs.
The bestbefore
macro addresses this challenge by providing a compile-time mechanism to:
- Mark code with expiration dates
- Enforce deadlines with compiler feedback
- Manage technical debt systematically
Unlike comments or documentation that can be easily overlooked, this macro integrates with the Rust compiler to actively enforce code maintenance policies.
§Usage
use bestbefore::bestbefore;
// Generate a warning if compiled after March 2024
#[bestbefore("03.2024")]
fn legacy_function() {
// ...
}
// Generate a warning if compiled after January 2023
// Cause a compilation error if compiled after December 2023
#[bestbefore("01.2023", expires = "12.2023")]
fn very_old_function() {
// ...
}
// Only specify an expiration date (for code that should just be removed by a deadline)
#[bestbefore(expires = "01.2028")]
fn expires_only_function() {
// ...
}
// Add a custom message to the warning
#[bestbefore("02.2023", message = "Please use new_api() instead")]
fn deprecated_with_message() {
// ...
}
§Date format
The macro uses the “MM.YYYY” format for simplicity, for example:
- “03.2024” represents March 2024
- “12.2023” represents December 2023
The day is assumed to be the first of the month.
§Environment variable
You can override the current date by setting the BESTBEFORE_DATE
environment variable,
which is useful for testing. The value should be in the same “MM.YYYY” format.
Attribute Macros§
- bestbefore
- A procedural macro that generates warnings or errors at compile time when the compile date exceeds the specified expiration date.