Skip to content
Snippets Groups Projects
Commit 5b5b4bbb authored by Nick Mathewson's avatar Nick Mathewson :game_die:
Browse files

Simplify advance and reset functions with mem::replace.

parent eab0046d
No related branches found
No related tags found
1 merge request!511DirMgr: Revise error handling to better tolerate reset-able failures
......@@ -594,18 +594,14 @@ pub(crate) async fn download<R: Runtime>(
/// Replace `state` with `state.reset()`.
fn reset(state: &mut Box<dyn DirState>) {
let mut this_state: Box<dyn DirState> = Box::new(PoisonedState);
std::mem::swap(&mut this_state, state);
this_state = this_state.reset();
std::mem::swap(&mut this_state, state);
let cur_state = std::mem::replace(state, Box::new(PoisonedState));
*state = cur_state.reset();
}
/// Replace `state` with `state.advance()`.
fn advance(state: &mut Box<dyn DirState>) {
let mut this_state: Box<dyn DirState> = Box::new(PoisonedState);
std::mem::swap(&mut this_state, state);
this_state = this_state.advance();
std::mem::swap(&mut this_state, state);
let cur_state = std::mem::replace(state, Box::new(PoisonedState));
*state = cur_state.advance();
}
/// Helper: Clamp `v` so that it is no more than one week from `now`.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment