Skip to content

Commit e7aeb40

Browse files
committed
Add documentation to Bundle macro
Signed-off-by: Marcel Müller <[email protected]>
1 parent e980225 commit e7aeb40

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

crates/bevy_ecs/src/bundle.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,54 @@
22
//!
33
//! This module contains the [`Bundle`] trait and some other helper types.
44
5+
/// Derive the [`Bundle`] trait
6+
///
7+
/// You can apply this derive macro to structs that are
8+
/// composed of [`Component`]s or
9+
/// other [`Bundle`]s.
10+
///
11+
/// ## Attributes
12+
///
13+
/// Sometimes parts of the Bundle should not be inserted.
14+
/// Those can be marked with `#[bundle(ignore)]`, and they will be skipped.
15+
/// In that case, the field needs to implement [`Default`] unless you also ignore
16+
/// the [`BundleFromComponents`] implementation.
17+
///
18+
/// ```rust
19+
/// # use bevy_ecs::prelude::{Component, Bundle};
20+
/// # #[derive(Component)]
21+
/// # struct Hitpoint;
22+
/// #
23+
/// #[derive(Bundle)]
24+
/// struct HitpointMarker {
25+
/// hitpoints: Hitpoint,
26+
///
27+
/// #[bundle(ignore)]
28+
/// creator: Option<String>
29+
/// }
30+
/// ```
31+
///
32+
/// Some fields may be bundles that do not implement
33+
/// [`BundleFromComponents`]. In those cases you can either ignore it as above,
34+
/// or you can opt out the whole Struct by marking it as ignored with
35+
/// `#[bundle(ignore_from_components)]`.
36+
///
37+
/// ```rust
38+
/// # use bevy_ecs::prelude::{Component, Bundle, ChildOf, Spawn};
39+
/// # #[derive(Component)]
40+
/// # struct Hitpoint;
41+
/// # #[derive(Component)]
42+
/// # struct Marker;
43+
/// #
44+
/// use bevy_ecs::spawn::SpawnRelatedBundle;
45+
///
46+
/// #[derive(Bundle)]
47+
/// #[bundle(ignore_from_components)]
48+
/// struct HitpointMarker {
49+
/// hitpoints: Hitpoint,
50+
/// related_spawner: SpawnRelatedBundle<ChildOf, Spawn<Marker>>,
51+
/// }
52+
/// ```
553
pub use bevy_ecs_macros::Bundle;
654

755
use crate::{

0 commit comments

Comments
 (0)