Skip to main content

Module borrow

Module borrow 

Source
Expand description

The ledger of who holds a component.

Component values live in UnsafeCells, so the compiler cannot police aliasing between two access paths, and this ledger does. A claim is registered before any reference to a value is handed out and is released when the holder goes away; a claim that overlaps one already held panics, naming both sites. Nothing else checks aliasing at run time.

A claim covers either every row of one archetype, which is what a query over a scope asks for, or one row, which is what a single-entity lookup asks for. Two claims conflict when they name the same component type, at least one of them writes, and they can reach the same row: two single-row claims when they name the same entity, anything else when they name the same archetype.

The archetype granularity is deliberately conservative. A query cannot tell before iterating which rows of a mixed archetype a scope can see, so it claims the whole archetype; a single-entity claim on a row of that archetype is then refused even when the query would not have reached that row. Refusing a pair that would have been fine is the price of never allowing a pair that is not.

Claims are filed under the holder that made them rather than under individual ids, so a holder carries one word of ledger state and releases in one pass.

What a holder claims is what it asked a crate::PlanBuilder for: there is no separate declaration of reached components, so a query cannot claim less than it reads.

Re-exportsΒ§

use core::any::TypeId; πŸ”’
use core::panic::Location; πŸ”’
use crate::entity::Entity; πŸ”’
use crate::query::Ask; πŸ”’
use crate::query::Mode; πŸ”’
use crate::world::World; πŸ”’

StructsΒ§

BorrowLedger πŸ”’
Every claim currently held on a world’s components.
Claims πŸ”’
The claims one holder owns, released together when it is dropped.
Lease πŸ”’
One registered claim.

EnumsΒ§

Rows πŸ”’
Which rows a claim covers.

FunctionsΒ§

claim_archetype πŸ”’
Claim on archetype every component the asks named, shared or exclusive.
claim_row πŸ”’
Claim on one entity’s row every component the asks named.