Skip to content

Commit 5d3f450

Browse files
authored
Merge pull request #71 from sacherjj/clippy-update
Updates for clippy
2 parents 0a65a4c + 7ee8353 commit 5d3f450

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.85.1"
3+
components = ["clippy", "rustfmt"]

src/launcher.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,21 @@ impl Launcher {
200200
/// Tries to load the stored state from disk.
201201
fn try_load_state(&self) -> Result<Option<State>> {
202202
let state_path = self.state_path();
203-
state_path
204-
.exists()
205-
.then(|| {
206-
debug!(path=%state_path.display(), "trying to read stored state");
207-
let contents = utils::map_and_log_error(
208-
fs::read_to_string(&state_path),
209-
format!("failed to read {}", state_path.display()),
210-
)?;
211-
212-
Ok(Some(utils::map_and_log_error(
213-
toml::from_str(&contents),
214-
format!("failed to parse {}", state_path.display()),
215-
)?))
216-
})
217-
.unwrap_or_else(|| {
218-
debug!(path=%state_path.display(), "stored state doesn't exist");
219-
Ok(None)
220-
})
203+
if state_path.exists() {
204+
debug!(path=%state_path.display(), "trying to read stored state");
205+
let contents = utils::map_and_log_error(
206+
fs::read_to_string(&state_path),
207+
format!("failed to read {}", state_path.display()),
208+
)?;
209+
210+
Ok(Some(utils::map_and_log_error(
211+
toml::from_str(&contents),
212+
format!("failed to parse {}", state_path.display()),
213+
)?))
214+
} else {
215+
debug!(path=%state_path.display(), "stored state doesn't exist");
216+
Ok(None)
217+
}
221218
}
222219

223220
/// Writes `self` to the hard-coded location as a TOML-encoded file.
@@ -418,7 +415,7 @@ impl Launcher {
418415
info!("running shutdown script at {}.", SHUTDOWN_SCRIPT_PATH);
419416
let status = utils::map_and_log_error(
420417
Command::new(SHUTDOWN_SCRIPT_PATH).status(),
421-
format!("couldn't execute script at {}", SHUTDOWN_SCRIPT_PATH),
418+
format!("couldn't execute script at {SHUTDOWN_SCRIPT_PATH}"),
422419
)?;
423420
status.code().unwrap_or_else(|| {
424421
error!("shutdown script was terminated by a signal.");

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ fn stop_child() {
4242
fn panic_hook(info: &PanicHookInfo) {
4343
let backtrace = Backtrace::new();
4444

45-
eprintln!("{:?}", backtrace);
45+
eprintln!("{backtrace:?}");
4646

4747
// Print panic info.
4848
if let Some(&string) = info.payload().downcast_ref::<&str>() {
49-
eprintln!("node panicked: {}", string);
49+
eprintln!("node panicked: {string}");
5050
} else {
51-
eprintln!("{}", info);
51+
eprintln!("{info}");
5252
}
5353

5454
stop_child()
@@ -80,7 +80,7 @@ fn main() -> Result<()> {
8080
.long("force-version")
8181
.value_name("version")
8282
.help("Forces the launcher to run the specified version of the node, for example \"1.2.3\"")
83-
.validator(|arg: &str| Version::from_str(arg).map_err(|_| format!("unable to parse '{}' as version", arg)))
83+
.validator(|arg: &str| Version::from_str(arg).map_err(|_| format!("unable to parse '{arg}' as version")))
8484
.required(false)
8585
.takes_value(true),
8686
)

src/utils.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,20 @@ pub(crate) fn versions_from_path<P: AsRef<Path>>(dir: P) -> Result<BTreeSet<Vers
111111

112112
/// Runs the given command as a child process.
113113
pub(crate) fn run_node(mut command: Command) -> Result<NodeExitCode> {
114-
let mut child = map_and_log_error(command.spawn(), format!("failed to execute {:?}", command))?;
114+
let mut child = map_and_log_error(command.spawn(), format!("failed to execute {command:?}"))?;
115115
crate::CHILD_PID.store(child.id(), Ordering::SeqCst);
116116

117117
let exit_status = map_and_log_error(
118118
child.wait(),
119-
format!("failed to wait for completion of {:?}", command),
119+
format!("failed to wait for completion of {command:?}"),
120120
)?;
121121
match exit_status.code() {
122122
Some(code) if code == NodeExitCode::Success as i32 => {
123-
debug!("successfully finished running {:?}", command);
123+
debug!("successfully finished running {command:?}");
124124
Ok(NodeExitCode::Success)
125125
}
126126
Some(code) if code == NodeExitCode::ShouldDowngrade as i32 => {
127-
debug!("finished running {:?} - should downgrade now", command);
127+
debug!("finished running {command:?} - should downgrade now");
128128
Ok(NodeExitCode::ShouldDowngrade)
129129
}
130130
Some(code) if code == NodeExitCode::ShouldExitLauncher as i32 => {
@@ -135,8 +135,8 @@ pub(crate) fn run_node(mut command: Command) -> Result<NodeExitCode> {
135135
Ok(NodeExitCode::ShouldExitLauncher)
136136
}
137137
_ => {
138-
warn!(%exit_status, "failed running {:?}", command);
139-
bail!("{:?} exited with error", command);
138+
warn!(%exit_status, "failed running {command:?}");
139+
bail!("{command:?} exited with error");
140140
}
141141
}
142142
}
@@ -149,7 +149,7 @@ pub(crate) fn map_and_log_error<T, E: std::error::Error + Send + Sync + 'static>
149149
match result {
150150
Ok(t) => Ok(t),
151151
Err(error) => {
152-
warn!(%error, "{}", error_msg);
152+
warn!(%error, "{error_msg}");
153153
Err(Error::new(error).context(error_msg))
154154
}
155155
}
@@ -165,9 +165,9 @@ where
165165
// This function should ideally be replaced with `itertools::join()`.
166166
// However, currently, it is only used to produce a proper debug message,
167167
// which is not sufficient justification to add a dependency to `itertools`.
168-
let result = iterable.into_iter().fold(String::new(), |result, item| {
169-
format!("{}{}, ", result, item)
170-
});
168+
let result = iterable
169+
.into_iter()
170+
.fold(String::new(), |result, item| format!("{result}{item}, "));
171171
if result.is_empty() {
172172
result
173173
} else {

0 commit comments

Comments
 (0)