Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Arti
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Arti
Commits
5b5b4bbb
Commit
5b5b4bbb
authored
2 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Simplify advance and reset functions with mem::replace.
parent
eab0046d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!511
DirMgr: Revise error handling to better tolerate reset-able failures
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
crates/tor-dirmgr/src/bootstrap.rs
+4
-8
4 additions, 8 deletions
crates/tor-dirmgr/src/bootstrap.rs
with
4 additions
and
8 deletions
crates/tor-dirmgr/src/bootstrap.rs
+
4
−
8
View file @
5b5b4bbb
...
...
@@ -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`.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment