mirror of
https://github.com/bevyengine/bevy
synced 2024-12-25 20:43:07 +00:00
67aa2953d0
# Objective In simple cases we might want to derive the `ExtractComponent` trait. This adds symmetry to the existing `ExtractResource` derive. ## Solution Add an implementation of `#[derive(ExtractComponent)]`. The implementation is adapted from the existing `ExtractResource` derive macro. Additionally, there is an attribute called `extract_component_filter`. This allows specifying a query filter type used when extracting. If not specified, no filter (equal to `()`) is used. So: ```rust #[derive(Component, Clone, ExtractComponent)] #[extract_component_filter(With<Fuel>)] pub struct Car { pub wheels: usize, } ``` would expand to (a bit cleaned up here): ```rust impl ExtractComponent for Car { type Query = &'static Self; type Filter = With<Fuel>; type Out = Self; fn extract_component(item: QueryItem<'_, Self::Query>) -> Option<Self::Out> { Some(item.clone()) } } ``` --- ## Changelog - Added the ability to `#[derive(ExtractComponent)]` with an optional filter. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |