Simplify advance and reset functions with mem::replace.
This commit is contained in:
parent
eab0046d0e
commit
5b5b4bbbea
|
@ -594,18 +594,14 @@ pub(crate) async fn download<R: Runtime>(
|
||||||
|
|
||||||
/// Replace `state` with `state.reset()`.
|
/// Replace `state` with `state.reset()`.
|
||||||
fn reset(state: &mut Box<dyn DirState>) {
|
fn reset(state: &mut Box<dyn DirState>) {
|
||||||
let mut this_state: Box<dyn DirState> = Box::new(PoisonedState);
|
let cur_state = std::mem::replace(state, Box::new(PoisonedState));
|
||||||
std::mem::swap(&mut this_state, state);
|
*state = cur_state.reset();
|
||||||
this_state = this_state.reset();
|
|
||||||
std::mem::swap(&mut this_state, state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replace `state` with `state.advance()`.
|
/// Replace `state` with `state.advance()`.
|
||||||
fn advance(state: &mut Box<dyn DirState>) {
|
fn advance(state: &mut Box<dyn DirState>) {
|
||||||
let mut this_state: Box<dyn DirState> = Box::new(PoisonedState);
|
let cur_state = std::mem::replace(state, Box::new(PoisonedState));
|
||||||
std::mem::swap(&mut this_state, state);
|
*state = cur_state.advance();
|
||||||
this_state = this_state.advance();
|
|
||||||
std::mem::swap(&mut this_state, state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper: Clamp `v` so that it is no more than one week from `now`.
|
/// Helper: Clamp `v` so that it is no more than one week from `now`.
|
||||||
|
|
Loading…
Reference in New Issue