jakobhellermann / bevy-inspector-egui

Inspector plugin for the bevy game engine
Apache License 2.0
1.12k stars 166 forks source link

derive InspectorOptions doesn't work with generics #109

Closed maxwellodri closed 1 year ago

maxwellodri commented 1 year ago

The following fails to compile.

#[derive(Debug, Clone, Reflect, FromReflect, InspectorOptions)]
#[reflect(InspectorOptions)]
pub struct TestStruct<T> {
    #[inspector(ignore)]
    t: PhantomData<T>,
}

Judging from what the derive macro expands to, it looks as if it doesn't handle generic bounds

jakobhellermann commented 1 year ago

Oh yeah, that should be fixed. Although in your case, I would just #[reflect(ignore)] the t field, since you don't really need PhantomData to be reflected.

jakobhellermann commented 1 year ago

anyways that was a pretty simple fix so this should work now: https://github.com/jakobhellermann/bevy-inspector-egui/commit/9e0590904c5bbff08c040243457bb85bc5546dba

#[derive(Reflect, InspectorOptions)]
struct Generic<T: 'static> {
    #[reflect(ignore)]
    _marker: PhantomData<fn() -> T>,

    #[inspector(min = 0.0)]
    other: f32,
}