Ability to undo once! macros
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Currently if you use the `once!` macro for logging something once, it will only log once. This is intended behavior.
However, in some cases you may want to undo the `once!` condition. For example: If you want to create an error message every time when a condition is first started.
## What solution would you like?
Not quite sure honestly, one solution is to add another condition that resets the internal `SHOULD_FIRE` variable:
```rs
macro_rules! undo_once {
($expression:expr, $condition:expr) => {{
use ::std::sync::atomic::{AtomicBool, Ordering};
static SHOULD_FIRE: AtomicBool = AtomicBool::new(true);
if SHOULD_FIRE.swap($condition, Ordering::Relaxed) {
$expression;
}
}};
}
```
## What alternative(s) have you considered?
Handling the variable myself.
Contributor guide
Research direction
The issue names the once! macro but provides no source file or test path. Start by locating that macro and reviewing how its internal SHOULD_FIRE state is scoped, then compare the proposed reset behavior with the existing manual alternative. Done means an agreed undo API with tests covering one-time logging and resetting it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100