GithubHelp home page GithubHelp logo

Comments (4)

benfrankel avatar benfrankel commented on June 29, 2024

Workaround:

trait Foo {
    fn foo() -> BoxedSystem {
        Box::new(IntoSystem::into_system(|| {}))
    }
}

from bevy.

benfrankel avatar benfrankel commented on June 29, 2024

This bug applies to run conditions as well, but BoxedCondition is not a proper workaround because it doesn't impl Condition. You have to use .run_if_dyn instead of .run_if, but .run_if_dyn is a real pain to use because it doesn't return Self:

fn my_system() {}

fn always_box() -> BoxedCondition {
    Box::new(IntoSystem::into_system(|| true))
}

fn foo(app: &mut App) {
    app.add_systems(Update, my_system.run_if(always_box())); // Does not compile
    app.add_systems(Update, {
        let mut configs = my_system.into_configs();
        configs.run_if_dyn(always_box());
        configs
    }); // Does compile
}

from bevy.

chescock avatar chescock commented on June 29, 2024

I think you need fn foo() -> impl Fn() + Sync + Send + 'static {.

System requires those trait bounds, and for ConcreteFoo the compiler can see the actual type and validate them. But for GenericFoo it has to protect against something like

struct EvilFoo;
impl Foo for EvilFoo {
    fn foo() -> impl Fn() {
        let x = Cell::new(0);
        // This is not `Sync` and so cannot be a `System`.
        move || {
            x.set(0);
        }
    }
}

from bevy.

benfrankel avatar benfrankel commented on June 29, 2024

Interesting. That works. I guess this isn't a bug in Rust or Bevy, but it is surprising.

from bevy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.