Skip to main content

ExtractComponent

Trait ExtractComponent 

pub trait ExtractComponent<L, F = ()>: SyncComponent<L, F>
where L: AppLabel,
{ type QueryData: ReadOnlyQueryData; type QueryFilter: QueryFilter; type Out: Bundle where <Self::Out as DynamicBundle>::Effect: NoBundleEffect; // Required method fn extract_component( item: <Self::QueryData as QueryData>::Item<'_, '_>, ) -> Option<Self::Out>; }
Expand description

Describes how a component gets extracted from the main app to a sub app.

Therefore the component is transferred from the “app world” into the “sub world” in the ExtractSchedule step. This functionality is enabled by adding [ExtractComponentPlugin] with the component type.

The Out type is defined in SyncComponent.

The marker type F is only used as a way to bypass the orphan rules. To implement the trait for a foreign type you can use a local type as the marker, e.g. the type of the plugin that calls [ExtractComponentPlugin].

Required Associated Types§

type QueryData: ReadOnlyQueryData

ECS [ReadOnlyQueryData] to fetch the components to extract.

type QueryFilter: QueryFilter

Filters the entities with additional constraints.

type Out: Bundle where <Self::Out as DynamicBundle>::Effect: NoBundleEffect

The output from extraction, i.e. ExtractComponent::extract_component.

The output components won’t be removed automatically from the sub world if the implementing component is removed, unless you set them in the SyncComponent::Target.

Required Methods§

fn extract_component( item: <Self::QueryData as QueryData>::Item<'_, '_>, ) -> Option<Self::Out>

Defines how the component is transferred into the “sub world”.

Returning None based on the queried item will remove the SyncComponent::Target from the entity in the sub world.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§