bevyengine / bevyengine/bevy

has_ever_changed and erase_change_history APIs for Ref<>-likes.

Open
#18,842 1 comment 0 reactions 0 assignees View on GitHub
A-ECS C-Feature S-Ready-For-Implementation X-Contentious
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

This is a generalization of APIs I've already written for bevy-convars, https://docs.rs/bevy-convars/0.2.0/bevy_convars/defaults/trait.IsDefault.html and https://docs.rs/bevy-convars/0.2.0/bevy_convars/defaults/trait.IsDefaultMut.html, where the functionality is used to track whether or not a CVar resource is still its initial (default) value.

## What solution would you like?

These APIs are equivalent to checking if some ref is its initial value, and removing and reinserting that value so that `added == changed` and it appears to be its initial value again.

Erasing change history additionally triggers change detection in a way that makes the value appear to have been inserted for the first time.

This would involve two new APIs on `Ref<>`-like types:

```rs
/// Returns whether or not the reference has ever been modified.
fn has_ever_changed(&self) -> bool

/// Erases the change history of the reference, effectively removing and re-inserting it without doing any work.
fn erase_change_history(&mut self)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.