Skip to content

Mutable access control for components #1635

@alice-i-cecile

Description

@alice-i-cecile

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

Right now, if you want to guarantee true type-level invariants on some of your data, you have to stuff it all together in a container type, and then provide public functions that do the relevant mutation while upholding the required invariants.

Splitting up such a monolithic container into smaller types allows more concurrent read access to the data, but also risks mis-using mutable access for these types.

-@JeanMertz on Discord

What solution would you like?

@TheRawMeatball thinks this could be done with derives for components, allowing you to export immutable-only variants of components for use elsewhere in your game.

What alternative(s) have you considered?

Use pub to control mutable access. Unfortunately, this restricts both immutable and mutable access in the same way, preventing us from reading the component elsewhere. This is an important distinction, since read-only access is much less likely to create horrifying spaghetti code.

Additional context

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-User-ErrorThis issue was caused by a mistake in the user's approach

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions