-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
A-ReflectionRuntime information about typesRuntime information about typesC-FeatureA new feature, making something new possibleA new feature, making something new possible
Description
What problem does this solve or what need does it fill?
For a simple struct with no generic trait bounds, like so, the reflect derive works.
#[derive(Reflect)]
struct MyStruct;For a struct with one or more generic trait bounds, like so, the reflect derive does not work.
#[derive(Reflect)]
struct MyStruct<T>(PhantomData<T>);This is because T isn't bound to be Reflect, which makes sense.
Adding a Reflect bound to T would fix this use case.
However, if T may or may not be Reflect, the overall struct cannot derive Reflect.
Normally this could be solved with impl<T: Reflect> Reflect for MyStruct<T>, except that Reflect is a very dangerous and unsafe to implement trait: #[derive(Reflect)] is the "correct" way to implement Reflect.
There should be some way to derive Reflect with additional bounds.
What solution would you like?
Something like an attribute:
#[derive(Reflect)]
#[reflect(where = "T") // Only implements Reflect when `T` is reflect.
struct MyStruct<T>(PhantomData<T>);This could be used multiple times.
#[derive(Reflect)])
#[reflect(where = "T", where = "Z")]
struct MyStruct<T, Z>(PhantomData<(T, Z)>);Metadata
Metadata
Assignees
Labels
A-ReflectionRuntime information about typesRuntime information about typesC-FeatureA new feature, making something new possibleA new feature, making something new possible