Skip to content

Update/change fields of a reflected/dynamic type #14850

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

Open
DasLixou opened this issue Aug 21, 2024 · 1 comment
Open

Update/change fields of a reflected/dynamic type #14850

DasLixou opened this issue Aug 21, 2024 · 1 comment
Labels
A-Reflection Runtime information about types C-Feature A new feature, making something new possible D-Complex Quite challenging from either a design or technical perspective. Ask for help!

Comments

@DasLixou
Copy link
Contributor

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

I can only get a &mut dyn Reflect from field_mut from DynamicTupleStruct (and similar) which I can modify, but e.g. changing the field from being a DynamicStruct to a DynamicEnum isn't possible.

What solution would you like?

Add the option to replace fields

What alternative(s) have you considered?

I currently have no idea of how to do that externally..

Additional context

Might be easier when unifying fields (#14847 (comment)) ?

@DasLixou DasLixou added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Aug 21, 2024
@MrGVSV MrGVSV added A-Reflection Runtime information about types D-Complex Quite challenging from either a design or technical perspective. Ask for help! and removed S-Needs-Triage This issue needs to be labelled labels Aug 21, 2024
@MrGVSV
Copy link
Member

MrGVSV commented Aug 21, 2024

The possible desire for this actually came up recently in #14776 where we'd want to have a way to replace Box<dyn Reflect> fields with a different Box<dyn Reflect>.

However, for this I think it might be cleaner to introduce this ability on the dynamic types directly (i.e. add a DynamicStruct::replace_field method). Then we'd need to add the ability to somehow downcast a dyn PartialReflect to one of the dynamic types.

I think it should be okay to move the dyn Any conversion methods from Reflect to PartialReflect since that doesn't necessarily break the contract that dyn Reflect is never a dynamic type. That would allow us to either modify the downcast methods on dyn PartialReflect to use dyn Any instead of dyn Reflect or just tell users to cast to dyn Any manually if they want to downcast to a dynamic type.


Edit: I misinterpreted the original issue to mean "add a way to replace the field on an arbitrary dyn Reflect value" rather than "add methods on the dynamic types to replace a field", which is what I ended up suggesting lol.

But yeah, I think we should only add such methods on the dynamic types instead of on Reflect/PartialReflect itself since it currently only makes sense in the context of dynamic types.

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-Feature A new feature, making something new possible D-Complex Quite challenging from either a design or technical perspective. Ask for help!
Projects
Status: Open
Development

No branches or pull requests

2 participants