Skip to content

Basic WorldCell docs #3389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions crates/bevy_ecs/src/world/world_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ use std::{
rc::Rc,
};

/// Exposes safe mutable access to multiple resources at a time in a World. Attempting to access
/// World in a way that violates Rust's mutability rules will panic thanks to runtime checks.
/// Exposes safe mutable access to multiple resources at a time in a World.
///
/// Attempting to access World in a way that violates Rust's mutability rules
/// will panic thanks to runtime checks.
///
/// NOTE: Currently, this only exposes methods to access resources.
/// Consider using [SystemState](crate::system::function_system::SystemState) instead
/// if you need to access entity-component data as well.
pub struct WorldCell<'w> {
pub(crate) world: &'w mut World,
pub(crate) access: Rc<RefCell<ArchetypeComponentAccess>>,
}

/// A set of ECS data that is or would be accessed, stored at an archetype-component level of granularity
pub(crate) struct ArchetypeComponentAccess {
access: SparseSet<ArchetypeComponentId, usize>,
}
Expand Down Expand Up @@ -78,6 +85,7 @@ impl<'w> Drop for WorldCell<'w> {
}
}

/// A runtime-checked read-only borrow of the [World], used by [WorldCell]
pub struct WorldBorrow<'w, T> {
value: &'w T,
archetype_component_id: ArchetypeComponentId,
Expand Down Expand Up @@ -120,6 +128,7 @@ impl<'w, T> Drop for WorldBorrow<'w, T> {
}
}

/// A runtime-checked mutable borrow of the [World], used by [WorldCell]
pub struct WorldBorrowMut<'w, T> {
value: Mut<'w, T>,
archetype_component_id: ArchetypeComponentId,
Expand Down