Skip to content

Commit 7d2348c

Browse files
committed
add doc comment about newtype component
1 parent df20dd5 commit 7d2348c

File tree

1 file changed

+7
-0
lines changed
  • crates/bevy_ecs/src/component

1 file changed

+7
-0
lines changed

crates/bevy_ecs/src/component/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ use thiserror::Error;
1616
///
1717
/// Any type that is `Send + Sync + 'static` can implement `Component` using `#[derive(Component)]`.
1818
///
19+
/// In order to use foreign types as components, wrap them using a newtype pattern.
20+
/// ```
21+
/// # use bevy_ecs::component::Component;
22+
/// use std::time::Duration;
23+
/// #[derive(Component)]
24+
/// struct Cooldown(Duration);
25+
/// ```
1926
/// Components are added with new entities using [`Commands::spawn`](crate::system::Commands::spawn),
2027
/// or to existing entities with [`EntityCommands::insert`](crate::system::EntityCommands::insert),
2128
/// or their [`World`](crate::world::World) equivalents.

0 commit comments

Comments
 (0)