bevy_extract_macros/lib.rs
1#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4mod extract_component;
5mod extract_resource;
6
7use bevy_macro_utils::BevyManifest;
8use proc_macro::TokenStream;
9
10pub(crate) fn bevy_extract_path() -> syn::Path {
11 BevyManifest::shared(|manifest| manifest.get_path("bevy_extract"))
12}
13
14#[proc_macro_derive(ExtractResource, attributes(extract_app))]
15pub fn derive_extract_resource(input: TokenStream) -> TokenStream {
16 extract_resource::derive_extract_resource(input)
17}
18
19/// Implements `ExtractComponent` trait for a component.
20///
21/// The component must implement [`Clone`].
22/// The component will be extracted into the sub world via cloning.
23/// Note that this only enables extraction of the component, it does not execute the extraction.
24/// See `ExtractComponentPlugin` to actually perform the extraction.
25///
26/// If you only want to extract a component conditionally, you may use the `extract_component_filter` attribute.
27/// To specify `SyncComponent::Target`, you can use the `extract_component_sync_target` attribute.
28///
29/// # Example
30///
31/// ```no_compile
32/// use bevy_ecs::component::Component;
33/// use bevy_extract_macros::ExtractComponent;
34///
35/// #[derive(Component, Clone, ExtractComponent)]
36/// #[extract_component_filter(With<Camera>)]
37/// #[extract_component_sync_target((Self, OtherNeedsCleanup))]
38/// pub struct Foo {
39/// pub should_foo: bool,
40/// }
41///
42/// // Without a filter (unconditional).
43/// #[derive(Component, Clone, ExtractComponent)]
44/// pub struct Bar {
45/// pub should_bar: bool,
46/// }
47/// ```
48#[proc_macro_derive(
49 ExtractComponent,
50 attributes(extract_component_filter, extract_component_sync_target, extract_app)
51)]
52pub fn derive_extract_component(input: TokenStream) -> TokenStream {
53 extract_component::derive_extract_component(input)
54}