/// Rewinds checkpoints by `steps_back` elements and returns the last checkpoint.
Rewinds checkpoints by `steps_back` elements and returns the last checkpoint.
Rewinds checkpoints by ` steps_back ` elements and returns the last checkpoint .
pub fn rewind_checkpoints<T>(checkpoints: &mut T, steps_back: usize) -> Result<MerkleCheckPoint, ChainStorageError>
where
    T: ArrayLike<Value = MerkleCheckPoint> + ArrayLikeExt<Value = MerkleCheckPoint>,
    ChainStorageError: From<T::Error>,
{
    let cp_count = checkpoints.len()?;
    assert!(cp_count > 0, "rewind_checkpoints: `checkpoints` is empty.");
    let rewind_len = cmp::max(cp_count.saturating_sub(steps_back), 1);
    checkpoints.truncate(rewind_len)?;
    let last_cp = checkpoints
        .get(rewind_len - 1)?
        .expect("rewind_checkpoints: `checkpoints` is empty after truncate");
    Ok(last_cp)
}
pub fn rewind_checkpoints < T > ( checkpoints : & mut T , steps_back : usize ) -> Result < MerkleCheckPoint , ChainStorageError > where T : ArrayLike < Value = MerkleCheckPoint > + ArrayLikeExt < Value = MerkleCheckPoint > , ChainStorageError : From < T :: Error > , { let cp_count = checkpoints . len ( ) ? ; assert ! ( cp_count 0 " " ) ; let rewind_len = cmp :: max ( cp_count . saturating_sub ( steps_back ) , 1 ) ; checkpoints . truncate ( rewind_len ) ? ; let last_cp = checkpoints . get ( rewind_len - 1 ) ? . expect ( " " ) ; Ok ( last_cp ) }
Rewinds checkpoints by `steps_back` elements and returns the last checkpoint.
Rewinds checkpoints by ` steps_back ` elements and returns the last checkpoint .
checkpoints
&mut T
steps_back
usize