bevyengine / bevyengine/bevy

Field setters for `DynamicTuple` and `DynamicTupleStruct`

Open
#18,698 3 comments 0 reactions 0 assignees View on GitHub
A-Reflection C-Feature D-Straightforward S-Ready-For-Implementation X-Uncontroversial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

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

There is no way to:

- replace fields that were already set
- add fields in any order other then first to last
- remove fields that were previously inserted

## What solution would you like?

I would like to see methods for setting fields by index and for removing fields.

```rust
fn insert_boxed_at(&mut self, index: usize, value: Box) -> Option>;
fn insert_at(&mut self, index: usize, value: T) -> Option>;
fn remove(&mut self, index: usize) -> Option>
```

## What alternative(s) have you considered?

Using a different struct to represent tuples this way.

## Additional context

This would probably require changing the internal `Vec>` to `Vec>>` to handle empty fields in middle. This raises the question of what the behavior of `iter_fields` should be.
Some possibilities:
* skip empty fields, this seems like the simplest thing to do, but doesn't feel correct
* iterate over `Option>`, this would be a breaking change
* Add a new type implementing `PartialReflect` be added that is a placeholder for `None`, I am not sure what the consequences of this would be

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.