Skip to content

Solution for multiple mutable field accesses #1

Open
@michaelsproul

Description

@michaelsproul

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),
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions