-
Notifications
You must be signed in to change notification settings - Fork 3
Add auto_add_plugin from bevy-butler
#46
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
Conversation
|
Oh, nice, this looks really good. Hopefully, it wasn't too much of a hassle. I agree with the I'm not opposed to adding the ability to attach these to use statements like |
crates/bevy_auto_plugin_shared/src/macro_api/attributes/actions/auto_add_plugin.rs
Outdated
Show resolved
Hide resolved
crates/bevy_auto_plugin_shared/src/macro_api/attributes/actions/auto_add_plugin.rs
Show resolved
Hide resolved
|
...New problem. Deriving #[derive(AutoPlugin)]
#[auto_plugin(impl_generic_auto_plugin_trait)]
#[auto_add_plugin(plugin = TestPlugin, generics(usize), init = TestSubPlugin(1))]
struct TestSubPlugin<T>(T);
impl<T: Send + Sync + Clone + 'static> Plugin for TestSubPlugin<T> {
#[auto_plugin]
fn build(&self, app: &mut App) {
app.insert_resource(Test(self.0.clone()));
}
}expands to (roughly) impl<T> AutoPlugin for TestSubPlugin<T> {} //! The trait bound `TestSubPlugin<T>: Plugin` is not satisfied
impl<T: Send + Sync + Clone + 'static> Plugin for TestSubPlugin<T> {
fn build(&self, app: &mut App) {
<Self as AutoPlugin>::build(self, app);
{
app.insert_resource(Test(self.0.clone()));
}
}
}(Honestly imo I could add |
|
Iirc you can't have both manual impl and the There's an existing auto_plugin_with_generics test that should still be passing I think? But the main goal was making the params additive. I'll be able to take a closer look later tonight. Edit: also possibility I'm misreading via phone lol |
|
I'm manually impling ...But also it turns out that |
…oPlugin: Plugin`
|
Oh I think it's because you need to constrain struct TestSubPlugin<T>(T)
where
T: Send + Sync + Clone + 'static
;DiffIndex: crates/bevy_auto_plugin_shared/src/__private/auto_plugin_registry.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/crates/bevy_auto_plugin_shared/src/__private/auto_plugin_registry.rs b/crates/bevy_auto_plugin_shared/src/__private/auto_plugin_registry.rs
--- a/crates/bevy_auto_plugin_shared/src/__private/auto_plugin_registry.rs (revision Staged)
+++ b/crates/bevy_auto_plugin_shared/src/__private/auto_plugin_registry.rs (date 1760580139343)
@@ -65,7 +65,7 @@
}
}
-pub trait AutoPlugin: AutoPluginTypeId {
+pub trait AutoPlugin: bevy_app::Plugin + AutoPluginTypeId {
#[inline]
fn name(&self) -> &'static str {
Self::static_name()
Index: tests/e2e/auto_add_plugin_with_generics_and_default_init.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/e2e/auto_add_plugin_with_generics_and_default_init.rs b/tests/e2e/auto_add_plugin_with_generics_and_default_init.rs
--- a/tests/e2e/auto_add_plugin_with_generics_and_default_init.rs (revision Staged)
+++ b/tests/e2e/auto_add_plugin_with_generics_and_default_init.rs (date 1760580175994)
@@ -10,7 +10,9 @@
#[derive(AutoPlugin)]
#[auto_plugin(impl_generic_auto_plugin_trait)]
#[auto_add_plugin(plugin = TestPlugin, generics(usize), init)]
-struct TestSubPlugin<T: 'static>(T);
+struct TestSubPlugin<T>(T)
+where
+ T: Send + Sync + Clone + 'static;
impl<T: Send + Sync + Clone + 'static> Plugin for TestSubPlugin<T> {
#[auto_plugin]
Index: tests/e2e/auto_add_plugin_with_generics_and_init.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/e2e/auto_add_plugin_with_generics_and_init.rs b/tests/e2e/auto_add_plugin_with_generics_and_init.rs
--- a/tests/e2e/auto_add_plugin_with_generics_and_init.rs (revision Staged)
+++ b/tests/e2e/auto_add_plugin_with_generics_and_init.rs (date 1760580160367)
@@ -10,7 +10,9 @@
#[derive(AutoPlugin)]
#[auto_plugin(impl_generic_auto_plugin_trait)]
#[auto_add_plugin(plugin = TestPlugin, generics(usize), init = TestSubPlugin(1))]
-struct TestSubPlugin<T: 'static>(T);
+struct TestSubPlugin<T>(T)
+where
+ T: Send + Sync + Clone + 'static;
impl<T: Send + Sync + Clone + 'static> Plugin for TestSubPlugin<T> {
#[auto_plugin] |
#34 looks really nice, might as well help!
Copied most of the
insert_resourcestuff for this. I made the initial value optional, callingdefault()when it'sNone.A couple weird points,
insert_resourcehasresourceas its init value key, but sincepluginis taken by the plugin to add stuff to, I didvalueinstead, but I'm not sure about this. For reference, butler calls all the init value keysinit, and for this specific attribute it calls the plugin to add stuff toto_pluginto avoid confusion with the value plugin.