bevy icon indicating copy to clipboard operation
bevy copied to clipboard

impl Deref for State<S>

Open Aceeri opened this issue 2 years ago • 3 comments

Objective

State requires a kind of awkward state.0 to get the current state when we could just have it deref into it, given it is just a thin wrapper type.

Solution

impl Deref for State

Aceeri avatar Mar 09 '23 22:03 Aceeri

The field in there should really be private too 🤔 Should we make that change here, or in a new PR?

alice-i-cecile avatar Mar 09 '23 22:03 alice-i-cecile

The field in there should really be private too 🤔 Should we make that change here, or in a new PR?

I'll just make the change here because yeah, otherwise its a bit error prone for setting the next state.

Aceeri avatar Mar 09 '23 22:03 Aceeri

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy? It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

github-actions[bot] avatar Mar 09 '23 22:03 github-actions[bot]

Idk if this is a win. It forces the "double star deref" for the State resource:

// before
fn system_1(state: Res<State<AppState>>) {
    if state.0 == AppState::InGame {
        info!("do thing");
    }
}

// after
fn system(state: Res<State<AppState>>) {
    if **state == AppState::InGame {
        info!("do thing");
    }
}

cart avatar Mar 21 '23 20:03 cart

I think it's important to make the field private, but I would be fine with a getter instead.

alice-i-cecile avatar Mar 21 '23 21:03 alice-i-cecile

Yeah I think a getter is preferable to double star

cart avatar Mar 23 '23 03:03 cart