Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for multiple mutable field accesses #1

Open
michaelsproul opened this issue Mar 17, 2021 · 0 comments
Open

Solution for multiple mutable field accesses #1

michaelsproul opened this issue Mar 17, 2021 · 0 comments

Comments

@michaelsproul
Copy link
Member

Unlike regular fields, superstruct's mutable getters don't lend themselves to disjoint mutable borrows, i.e. borrowing field1 and field2 simultaneously, where at least one of the borrows is mutable.

This can be worked around on a case-by-case basis by writing helper functions like this, but I wonder if we should generate these automatically for given pairs/lists of fields:

/// Convenience accessor for validators and balances simultaneously.
pub fn validators_and_balances_mut(&mut self) -> (&mut [Validator], &mut [u64]) {
    match self {
        BeaconState::Base(state) => (&mut state.validators, &mut state.balances),
        BeaconState::Altair(state) => (&mut state.validators, &mut state.balances),
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant