bevyengine / bevyengine/bevy

Ability to undo once! macros

Open
#11,374 7 comments 0 reactions 0 assignees View on GitHub
A-Diagnostics C-Usability
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.