Trait andys_morning_stroll::RandomWalk
source · pub trait RandomWalk {
type State: PartialEq + Clone;
// Required methods
fn make_move<R: Rng>(&mut self, rng: &mut R);
fn get_state(&self) -> Self::State;
fn set_state(&mut self, state: Self::State);
// Provided methods
fn walk<R: Rng>(
&mut self,
src: Self::State,
tgt: Self::State,
rng: &mut R
) -> u32 { ... }
fn walk_until_limit<R: Rng>(
&mut self,
src: Self::State,
tgt: Self::State,
rng: &mut R,
limit: u32
) -> Result<u32, u32> { ... }
}Expand description
Implement random walks on a state machine.
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn walk<R: Rng>(
&mut self,
src: Self::State,
tgt: Self::State,
rng: &mut R
) -> u32
fn walk<R: Rng>( &mut self, src: Self::State, tgt: Self::State, rng: &mut R ) -> u32
Perform a random walk, starting at src, and making random moves until the tgt state is
reached. This does not terminate at zero steps if src and tgt are the same, a move is
always made first before continuing until tgt.
Returns the number of steps it took. This method could block forever if the state
diverges somehow and never arrives at tgt. See also walk_until_limit.
sourcefn walk_until_limit<R: Rng>(
&mut self,
src: Self::State,
tgt: Self::State,
rng: &mut R,
limit: u32
) -> Result<u32, u32>
fn walk_until_limit<R: Rng>( &mut self, src: Self::State, tgt: Self::State, rng: &mut R, limit: u32 ) -> Result<u32, u32>
Same as walk_until, but also takes a limit parameter, specifying the maximum length of
the walk we should allow before bailing out. Returns Ok(num_steps) if tgt is reached at or
before the limit, and Err(limit) otherwise.
Panics
Panics if limit is zero.