| Crates.io | bestbefore |
| lib.rs | bestbefore |
| version | 0.1.0 |
| created_at | 2025-03-07 23:08:31.224844+00 |
| updated_at | 2025-03-07 23:08:31.224844+00 |
| description | A procedural macro for marking code with expiration dates |
| homepage | |
| repository | https://github.com/suprematic/bestbefore |
| max_upload_size | |
| id | 1583803 |
| size | 40,596 |
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:
Unlike comments or documentation that can be easily overlooked, this macro integrates with the Rust compiler to actively enforce code maintenance policies. It's especially valuable in larger teams and codebases where knowledge about legacy code may not be shared by all contributors.
The bestbefore macro helps manage code deprecation by adding compile-time warnings or errors based on specified dates:
expires parameter is provided and the compilation date is after that date, it causes a compilation failureAdd the following to your Cargo.toml:
[dependencies]
bestbefore = "0.1.0"
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() {
// ...
}
// Add a custom message to the warning
#[bestbefore("02.2023", message = "Please use new_api() instead")]
fn deprecated_with_message() {
// ...
}
// Apply to any kind of code block, not just functions
#[bestbefore("06.2023")]
mod legacy_module {
// The entire module will generate a warning
}
// Apply to structs as well
#[bestbefore("05.2023")]
struct OldStructure {
// ...
}
BESTBEFORE_DATE environment variable to override the current date (useful for testing)The macro enforces several rules for date handling:
Licensed under the Eclipse Public License 2.0 (EPL-2.0).