Skip to content

Possible to define a system as generic over SystemParam and provide concrete type? #3300

@shelbyd

Description

@shelbyd

Here's a minimal example of what I'm trying to do:

#![allow(dead_code)]

use bevy::prelude::*;
use bevy::ecs::system::SystemParam;

fn main() {
    App::build()
        .add_system(generic_system::<NullImpl>.system())
        .add_system(bound_generic_system.system())
        .run()
}

fn generic_system<T>(t: T) {}
fn bound_generic_system(t: NullImpl) {}

#[derive(SystemParam)]
pub struct NullImpl<'a> {
    marker: Res<'a, ()>,
}

AFAIU, the problem is that generic_system::<NullImpl> is implicitly binding NullImpl<'_>, so that it doesn't satisfy for<'a>. I would think it should work if I were able to write something like: generic_system::<for<'a> NullImpl<'a>>.system(), but that doesn't parse.

Is there something I can do to make this compile? I've tried to make a non-bevy example to ask the broader Rust community, but I haven't been able to reproduce.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions