Skip to main content

MemberId

Struct MemberId 

Source
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

Source

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 }
    }
}
Source

pub const fn seat(self) -> usize

Which seat of the cast this is, counting from zero.

The stepping order is seat order — see enlist — so this is the one thing a cart can read off an id: who moves before whom.

Trait Implementations§

Source§

impl Clone for MemberId

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MemberId

Source§

impl Debug for MemberId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MemberId

Source§

impl PartialEq for MemberId

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MemberId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.