pub fn rewrite<St: ?Sized, X, E>(
state: &mut St,
most: usize,
find: impl FnMut(&St) -> Result<Option<X>, E>,
apply: impl FnMut(&mut St, X) -> Result<(), E>,
) -> Result<Repeated<usize>, E>Expand description
Rewrites state until nothing is left to rewrite: find looks for the
next rewrite in it, apply makes the one found, and the search starts
over from the state that leaves — a rewrite changes what there is to
find. At most most searches, the last of which, in a run that is done,
finds nothing; done with how many rewrites were made.
find gets the state to read and apply to change, so a search can
hold on to borrows of the state that a rewrite could not coexist with.