You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.structMyStruct<T>(PhantomData<T>);
This could be used multiple times.
#[derive(Reflect)])#[reflect(where = "T", where = "Z")]structMyStruct<T,Z>(PhantomData<(T,Z)>);
The text was updated successfully, but these errors were encountered:
In this case, the derive macro will not add any additional bounds (well, except the bare minimum to make reflection work). So in the above example we have to ignore u since our custom bound doesn't add FromReflect as a trait bound (FromReflect is used sine we didn't specify #[reflect(from_reflect = false)]).
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.
For a struct with one or more generic trait bounds, like so, the reflect derive does not work.
This is because
T
isn't bound to beReflect
, which makes sense.Adding a
Reflect
bound toT
would fix this use case.However, if
T
may or may not beReflect
, the overall struct cannot deriveReflect
.Normally this could be solved with
impl<T: Reflect> Reflect for MyStruct<T>
, except thatReflect
is a very dangerous and unsafe to implement trait:#[derive(Reflect)]
is the "correct" way to implementReflect
.There should be some way to derive
Reflect
with additional bounds.What solution would you like?
Something like an attribute:
This could be used multiple times.
The text was updated successfully, but these errors were encountered: