Skip to content

Make drain take a mutable borrow instead of Box<Self> for reflected Map, List, and Set.#15406

Merged
alice-i-cecile merged 3 commits intobevyengine:mainfrom
andriyDev:drain
Sep 30, 2024
Merged

Make drain take a mutable borrow instead of Box<Self> for reflected Map, List, and Set.#15406
alice-i-cecile merged 3 commits intobevyengine:mainfrom
andriyDev:drain

Conversation

@andriyDev
Copy link
Copy Markdown
Contributor

Objective

Fixes #15185.

Solution

Change drain to take a &mut self for most reflected types.

Some notable exceptions to this change are Array and Tuple. These types don't make sense with drain taking a mutable borrow since they can't get "smaller". Also BTreeMap doesn't have a drain function, so we have to pop elements off one at a time.

Testing

  • The existing tests are sufficient.

Migration Guide

  • reflect::Map, reflect::List, and reflect::Set all now take a &mut self instead of a Box<Self>. Callers of these traits should add &mut before their boxes, and implementers of these traits should update to match.

…ed `Map`, `List`, and `Set`.

Some notable exceptions to this change are `Array` and `Tuple`. These types don't make sense with `drain` taking a mutable borrow since they can't get "smaller".
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 24, 2024
@BenjaminBrienen BenjaminBrienen added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it D-Straightforward Simple bug fixes and API improvements, docs, test and examples and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 25, 2024
Copy link
Copy Markdown
Contributor

@pablo-lua pablo-lua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a major upgrade of the api, its more simple to pass a mut reference. All good, lgtm

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 30, 2024
Merged via the queue into bevyengine:main with commit 04d5685 Sep 30, 2024
@andriyDev andriyDev deleted the drain branch September 30, 2024 18:37
robtfm pushed a commit to robtfm/bevy that referenced this pull request Oct 4, 2024
…ed `Map`, `List`, and `Set`. (bevyengine#15406)

# Objective

Fixes bevyengine#15185.

# Solution

Change `drain` to take a `&mut self` for most reflected types.

Some notable exceptions to this change are `Array` and `Tuple`. These
types don't make sense with `drain` taking a mutable borrow since they
can't get "smaller". Also `BTreeMap` doesn't have a `drain` function, so
we have to pop elements off one at a time.

## Testing

- The existing tests are sufficient.

---

## Migration Guide

- `reflect::Map`, `reflect::List`, and `reflect::Set` all now take a
`&mut self` instead of a `Box<Self>`. Callers of these traits should add
`&mut` before their boxes, and implementers of these traits should
update to match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make reflect::Map::drain and reflect::List::drain take a mutable borrow instead of Box<Self>.

7 participants