pub struct MemberId { /* private fields */ }Expand description
One member of a World’s cast: a seat, and the right to ask the world to
borrow whoever is in it.
What MemberBuilder::enlist hands back and the cart keeps beside its own game data.
Two bytes, Copy, and nothing else: the position, the velocity, the rectangle, the contacts
and the look are all the world’s, and every one of them is asked of the seat this id names,
borrowed from the world it was enlisted into — world.member(hero) to read
it, world.member_mut(hero) to change it.
struct Hero {
/// Where the hero is, how fast, and what it last ran into: all of it the world's.
member: MemberId,
/// And what is the cart's own, which the world has never heard of.
coins: u16,
}
let hero = Hero {
member: Member::builder(16.0, 80.0, 8, 8).enlist(world)?,
coins: 0,
};A member is only ever as good as its seat. retire empties the seat and
the id to it goes stale on the spot: asking the world to borrow anything with a stale one is a
bug in the cart, and it is answered with a panic naming the seat rather than with somebody
else’s position. A cart that would rather ask than know asks
get_member.
Ids are the world’s own: one from a different World means the seat of that number in
this one, which is a member the cart never meant. Carts with two scenes going at once keep
their ids with the world they came from.
A seat’s ids come round again: one let for the hundred and twenty-ninth time is handed the id it was handed the first time, and an id kept unasked-about across all of them would answer for whoever holds the seat now. Which is a way of saying: retire a member and forget it, the way a cart does anyway.
Implementations§
Source§impl MemberId
impl MemberId
Sourcepub const NOBODY: Self
pub const NOBODY: Self
An id for nobody: what a cart’s state holds for somebody not yet enlisted.
The seat it names is past the sixty-four the wire carries, so no world has it and no
enlist can ever hand it out. It is a const, which is the whole
point of it: a cart whose state is placed rather than built writes its actors
down as constants and gives them their seats in Game::boot, and this
is what they hold until it does.
Asking the world to borrow anything with it is the same bug as asking with a retired id, and panics the same way — an actor that was never seated is not standing anywhere.
struct Hero {
member: MemberId,
coins: u16,
}
impl Hero {
/// The hero as the cart ships: everything about it but a seat.
const fn waiting() -> Self {
Self { member: MemberId::NOBODY, coins: 0 }
}
}