Skip to content

Add non-send resources via Commands #1397

@willcrichton

Description

@willcrichton

What problem does this solve or what need does it fill?

I have a non-send resource (RustPython interpreter). It has a sufficiently complicated construction process such that I didn't want to run the constructor in Plugin::build, but rather have my plugin launch a startup system that would insert the non-send resource.

Right now, the only way to insert a non-send (thread-local) resource is either via AppBuilder, or via a thread-local system that directly manipulates Resources.

What solution would you like?

Using the Commands struct provides a more consistent way of managing resources outside of AppBuilder. As proposed by RawMeatball here, the API could look like:

fn forced_non_send_system(
  commands: &mut Commands,
  marker: NonSend<()>,
) {
  let custom_thing = Stuff::that_is_non_send();
  commands.insert_non_send_resource(&marker, custom_thing);
}

What alternative(s) have you considered?

Could just leave it the way it is. This isn't a necessity, but a nice bit of API consistency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions