-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
Reflect::type_descriptor
(#90)
The idea with `Reflect::type_descriptor` was to get the type descriptor for the reflected value however it had one big footgun: `<Value as Reflect>::type_descriptor` returns an opaque type, _not_ the type the `Value` was created from. For example: ```rust fn show_editor_ui(reflect: &mut dyn Reflect) { let type_descriptor = reflect.type_descriptor(); // show ui... } struct Foo {} let foo = Foo {}; // convert the `foo` into a `Value`, perhaps to serialize // it and send across FFI let mut foo_value = foo.to_value(); // because `Value` implements `Reflect` it works as a `&dyn mut Reflect` // but our `show_editor_ui` wont really work because we've lost the type // information when we called `foo.to_value()` show_editor_ui(&mut foo_value); ``` The solution is to capture the type descriptor explicitly and store that together with `foo_value`: ```rust fn show_editor_ui(reflect: &mut dyn Reflect, type_descriptor: TypeDescriptor) { // show ui... } // store and serialize both the value and the original type descriptor let mut foo_value = foo.to_value(); let foo_type_descriptor = <Foo as DescribeType>::type_descriptor(); show_editor_ui(&mut foo_value, foo_type_descriptor); ``` I think because of this it makes sense to remove `Reflect::type_descriptor` as it should make it easier to users to do the right thing. I also considered making a `TypedValue` that is like `Value` but preserves the type descriptor but I ran into a bunch of technical issues with that.
- Loading branch information
1 parent
8b6bfc6
commit 2e9834e
Showing
7 changed files
with
5 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters