Skip to main content

Tape

Struct Tape 

Source
pub struct Tape<I> { /* private fields */ }
Expand description

A recorded run: one intent per tick, plus the canonical world hash each tick left behind, both in tick order.

A tape is the artifact a bug report carries: the seed, what the player asked for on every tick, and what the world looked like. Serialisable, so it can be written next to the save it came from.

Implementations§

Source§

impl<I> Tape<I>

Source

pub const fn new(seed: u64) -> Self

An empty tape for a run seeded with seed.

The seed is carried because a tape without it is not replayable: the factory a replay is handed reads seed to rebuild the same starting world.

Source

pub const fn seed(&self) -> u64

The seed the recording run started from.

Source

pub fn ticks(&self) -> u64

How many ticks are recorded. What a replay runs.

Source

pub fn is_empty(&self) -> bool

Whether no tick has been recorded yet.

Source

pub fn intents(&self) -> &[I]

Every recorded intent, in tick order.

Source

pub fn intents_mut(&mut self) -> &mut [I]

Every recorded intent, to edit a tape before replaying it.

Rewriting a tick’s intent while keeping the recorded hashes is how a divergence is bisected: the replay then reports that tick (or says the edit changed nothing), instead of a hunt through a whole session.

Source

pub fn hashes(&self) -> &[u64]

Every recorded hash, in tick order. Shorter than the tape when the intent tail was never hashed.

Source

pub fn intent(&self, tick: u64) -> Option<&I>

The intent of tick, or None past the end.

Source

pub fn hash(&self, tick: u64) -> Option<u64>

The recorded world hash of tick, or None if that tick was not hashed.

Source

pub fn record_intent(&mut self, intent: I) -> u64

Appends one tick’s intent. Returns the tick it landed on.

Call it before the tick runs, so the tape is in the order the game saw.

Source

pub fn record_hash(&mut self, world_hash: u64)

Appends the canonical world hash of the tick just recorded, in tick order: tick n’s hash is the world after tick n ran.

A tape may stop hashing early (an intent-only tail cannot be verified, see verify), but never hashes twice for one tick, and never more hashes than ticks.

§Panics

If every recorded intent already has a hash. That is a recording loop hashing twice for one tick, which would misalign every later comparison.

Source§

impl<I> Tape<I>
where I: Clone + Send + Sync + 'static,

Source

pub fn replay<F>(&self, setup: F) -> Vec<u64>
where F: FnMut() -> Setup,

Replays the tape into a fresh world and returns the canonical hash of every tick, in tick order.

setup is called once per replay and must rebuild the same starting world every time, so a caller can replay one tape twice and diff the two logs itself, or compare them against a golden list.

Source

pub fn replay_with<F, C>(&self, setup: F, commit: C) -> Vec<u64>
where F: FnMut() -> Setup, C: FnMut(&mut World, &I),

replay, running commit on each tick’s intent after Intent is set and before the tick runs.

This is the hook for a game whose systems read their own action resources:

ⓘ
let commit = |world: &mut World, input: &Press| {
    world.resource_mut::<Keys>().0 = *input;
};
let hashes = tape.replay_with(|| fresh(seed), commit);
Source

pub fn verify<F>(&self, setup: F) -> Result<(), VerifyError>
where F: FnMut() -> Setup,

Replays the tape and compares every tick’s hash against the recording, returning the first tick that differs.

The replay stops at the divergence: a world that already disagrees is not worth stepping further, and a game that would panic on it panics here instead of reporting the tick it went wrong at. Pair this with record_intent and record_hash.

Source

pub fn verify_with<F, C>(&self, setup: F, commit: C) -> Result<(), VerifyError>
where F: FnMut() -> Setup, C: FnMut(&mut World, &I),

verify, running commit on each tick’s intent after Intent is set and before the tick runs.

Trait Implementations§

Source§

impl<I: Clone> Clone for Tape<I>

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<I: Debug> Debug for Tape<I>

Source§

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

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

impl<'de, I> Deserialize<'de> for Tape<I>
where I: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<I: Eq> Eq for Tape<I>

Source§

impl<I: PartialEq> PartialEq for Tape<I>

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<I> Serialize for Tape<I>
where I: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<I: PartialEq> StructuralPartialEq for Tape<I>

Auto Trait Implementations§

§

impl<I> Freeze for Tape<I>
where Vec<I>: Freeze,

§

impl<I> RefUnwindSafe for Tape<I>
where Vec<I>: RefUnwindSafe,

§

impl<I> Send for Tape<I>
where Vec<I>: Send,

§

impl<I> Sync for Tape<I>
where Vec<I>: Sync,

§

impl<I> Unpin for Tape<I>
where Vec<I>: Unpin,

§

impl<I> UnsafeUnpin for Tape<I>
where Vec<I>: UnsafeUnpin,

§

impl<I> UnwindSafe for Tape<I>
where Vec<I>: UnwindSafe,

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> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> Template for T
where T: Clone + Unpin,

Source§

type Output = T

The type of value produced by this Template.
Source§

fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>

Uses this template and the given entity context to produce a Template::Output.
Source§

fn clone_template(&self) -> T

Clones this template. See Clone.
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.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of self.