#impl Plugin doesn't work properly?

17 messages · Page 1 of 1 (latest)

viscid arrow
#

I'm trying to move a plugin I made out of my project and into it's own project, and all the code works in the seperate project, but not in this one?

I get this error:

error[E0277]: the trait bound `EasyConfigPlugin<Settings>: Plugins<_>` is not satisfied
    |
    |          ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `bevy::bevy_app::plugin::sealed::Plugins<_>` is not implemented for `EasyConfigPlugin<Settings>`, which is required by `EasyConfigPlugin<Settings>: Plugins<_>`
    |          |
    |          required by a bound introduced by this call
    |
    = note: required for `EasyConfigPlugin<Settings>` to implement `Plugins<_>`
note: required by a bound in `bevy::prelude::App::add_plugins`
   --> C:\Users\Ph03n\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_app-0.14.1\src\app.rs:543:52
    |
543 |     pub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut Self {
    |                                                    ^^^^^^^^^^ required by this bound in `App::add_plugins`

This is where Plugin is implemented:

impl<A> Plugin for EasyConfigPlugin<A>
where
    for<'de> A: serde::Deserialize<'de> + Asset + Resource + Clone + Default,
{
    fn build(&self, app: &mut App) {
        app
            .init_asset::<A>()
            .register_asset_loader(ConfigFileAssetLoader::<A> {
                _marker: PhantomData
            })
            .insert_resource(ConfigFileHolder::<A> {
                path: self.path,
                handle: None,
                _marker: PhantomData
            })
            .init_resource::<A>()
            .add_systems(Startup, add_asset_to_resource::<A>)
            .add_systems(Update, update_resource::<A>);
    }
}
#

This is the code that causes the error:

use bevy::prelude::*;
use bevy_easy_config::EasyConfigPlugin;
use serde::Deserialize;


fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(EasyConfigPlugin::<Settings>::new("settings.ron"))
        .add_systems(Update, print_on_keypress)
        .run();
}


#[derive(Deserialize, Asset, Resource, Clone, TypePath)]
struct Settings {
    action_keybind: KeyCode
}


fn print_on_keypress(
    settings: Res<Settings>,
    keyboard: Res<ButtonInput<KeyCode>>,
) {
    if keyboard.just_pressed(settings.action_keybind) {
        println!("You pressed: {:#?}", settings.action_keybind)
    }
}
shut reef
#

Missing Default for Settings perhaps?

viscid arrow
#

Yep that was it

#

Weird error for that?

shut reef
#

That's a Rust thing

viscid arrow
#

hmm

#

never tried it before

shut reef
#

Because your impl requires specific bounds

#

Your struct technically doesn't impl Plugin for that generic

viscid arrow
#

I would have thought it would error and say that the type doesn't implement Default

shut reef
#

You would need to write the bound a bit differently for that I think

#

But I'm not really familiar with rust's intrinsics

viscid arrow
#

Is that an easy rewrite or...?

#

ah ok

#

Thank you for the help <3

uncut quarry
#

I think if you moved the bounds to the definition of EasyConfigPlugin you might get a better error message. Because then Settings wouldn’t be possible as the generic type argument without implementing Default