Skip to content

Commit

Permalink
add an example
Browse files Browse the repository at this point in the history
  • Loading branch information
hymm committed Feb 11, 2024
1 parent 78aa75e commit 1981272
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions crates/bevy_ecs/src/system/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,45 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
/// are dropped, non-archetypal filters like `Added` and `Changed` will no be respected.
/// To maintain or change filter terms see `Self::join_filtered`.
///
/// ## Example
///
/// ```rust
/// # use bevy_ecs::prelude::*;
/// # use bevy_ecs::system::QueryLens;
/// #
/// # #[derive(Component)]
/// # struct Transform;
/// #
/// # #[derive(Component)]
/// # struct Player;
/// #
/// # #[derive(Component)]
/// # struct Enemy;
/// #
/// # let mut world = World::default();
/// # world.spawn((Transform, Player));
/// # world.spawn((Transform, Enemy));
///
/// fn system(
/// mut transforms: Query<&Transform>,
/// mut players: Query<&Player>,
/// mut enemies: Query<&Enemy>
/// ) {
/// let mut players_transforms: QueryLens<(&Transform, &Player)> = transforms.join(&mut players);
/// for (transform, player) in &players_transforms.query() {
/// // do something with a and b
/// }
///
/// let mut enemies_transforms: QueryLens<(&Transform, &Enemy)> = transforms.join(&mut enemies);
/// for (transform, enemy) in &enemies_transforms.query() {
/// // do something with a and b
/// }
/// }
///
/// # let mut schedule = Schedule::default();
/// # schedule.add_systems(system);
/// # schedule.run(&mut world);
/// ```
/// ## Panics
///
/// This will panic if `NewD` is not a subset of the union of the original fetch `Q` and `OtherD`.
Expand Down

0 comments on commit 1981272

Please sign in to comment.