Skip to content

Commit

Permalink
Basic EntityRef and EntityMut docs (#3388)
Browse files Browse the repository at this point in the history
# Objective

- `EntityRef` and `EntityMut` are surpisingly important public types when working directly with the `World`.
- They're undocumented.

## Solution

- Just add docs!
  • Loading branch information
alice-i-cecile committed Apr 25, 2022
1 parent 5155034 commit 4bcb310
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
};
use std::any::TypeId;

/// A read-only reference to a particular [`Entity`] and all of its components
pub struct EntityRef<'w> {
world: &'w World,
entity: Entity,
Expand Down Expand Up @@ -98,6 +99,7 @@ impl<'w> EntityRef<'w> {
}
}

/// A mutable reference to a particular [`Entity`] and all of its components
pub struct EntityMut<'w> {
world: &'w mut World,
entity: Entity,
Expand Down Expand Up @@ -464,6 +466,8 @@ impl<'w> EntityMut<'w> {
}

// TODO: move to Storages?
/// Get a raw pointer to a particular [`Component`] on a particular [`Entity`] in the provided [`World`].
///
/// # Safety
/// `entity_location` must be within bounds of the given archetype and `entity` must exist inside
/// the archetype
Expand Down Expand Up @@ -494,6 +498,8 @@ unsafe fn get_component(
}

// TODO: move to Storages?
/// Get a raw pointer to the [`ComponentTicks`] of a particular [`Component`] on a particular [`Entity`] in the provided [World].
///
/// # Safety
/// Caller must ensure that `component_id` is valid
#[inline]
Expand Down Expand Up @@ -566,6 +572,8 @@ unsafe fn take_component(
}
}

/// Get a raw pointer to a particular [`Component`] by [`TypeId`] on a particular [`Entity`] in the provided [`World`].
///
/// # Safety
/// `entity_location` must be within bounds of an archetype that exists.
unsafe fn get_component_with_type(
Expand All @@ -578,6 +586,8 @@ unsafe fn get_component_with_type(
get_component(world, component_id, entity, location)
}

/// Get a raw pointer to the [`ComponentTicks`] of a particular [`Component`] by [`TypeId`] on a particular [`Entity`] in the provided [`World`].
///
/// # Safety
/// `entity_location` must be within bounds of an archetype that exists.
pub(crate) unsafe fn get_component_and_ticks_with_type(
Expand Down

0 comments on commit 4bcb310

Please sign in to comment.