Skip to content

has_ever_changed and erase_change_history APIs for Ref<>-likes. #18842

Open
@moonheart08

Description

@moonheart08

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:

    /// 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!X-ContentiousThere are nontrivial implications that should be thought through

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions