style: simplify string formatting for readability (#231763)

* style: simplify string formatting for readability

* fix: formatting in `.rs` files in `src/`
This commit is contained in:
Hamir Mahal
2024-10-22 09:30:46 -07:00
committed by GitHub
parent aabb725c04
commit a744313eb7
29 changed files with 108 additions and 128 deletions

View File

@@ -133,7 +133,7 @@ fn apply_build_environment_variables() {
} else {
PathBuf::from_str(&v).unwrap()
};
println!("cargo:warning=loading product.json from <{:?}>", path);
println!("cargo:warning=loading product.json from <{path:?}>");
apply_build_from_product_json(&path);
}

View File

@@ -93,10 +93,9 @@ impl AuthProvider {
pub fn get_default_scopes(&self) -> String {
match self {
AuthProvider::Microsoft => format!(
"{}/.default+offline_access+profile+openid",
PROD_FIRST_PARTY_APP_ID
),
AuthProvider::Microsoft => {
format!("{PROD_FIRST_PARTY_APP_ID}/.default+offline_access+profile+openid")
}
AuthProvider::Github => "read:user+read:org".to_string(),
}
}
@@ -122,7 +121,7 @@ async fn get_github_user(
) -> Result<reqwest::Response, reqwest::Error> {
client
.get(GH_USER_ENDPOINT)
.header("Authorization", format!("token {}", access_token))
.header("Authorization", format!("token {access_token}"))
.header("User-Agent", get_default_user_agent())
.send()
.await
@@ -690,7 +689,7 @@ impl Auth {
}
let provider = prompt_options(
format!("How would you like to log in to {}?", PRODUCT_NAME_LONG),
format!("How would you like to log in to {PRODUCT_NAME_LONG}?"),
&[AuthProvider::Microsoft, AuthProvider::Github],
)?;

View File

@@ -153,7 +153,7 @@ fn print_and_exit<E>(err: E) -> !
where
E: std::fmt::Display,
{
log::emit(log::Level::Error, "", &format!("{}", err));
log::emit(log::Level::Error, "", &format!("{err}"));
std::process::exit(1);
}

View File

@@ -283,12 +283,12 @@ impl ExtensionSubcommand {
target.push("--show-versions".to_string());
}
if let Some(category) = &args.category {
target.push(format!("--category={}", category));
target.push(format!("--category={category}"));
}
}
ExtensionSubcommand::Install(args) => {
for id in args.id_or_path.iter() {
target.push(format!("--install-extension={}", id));
target.push(format!("--install-extension={id}"));
}
if args.pre_release {
target.push("--pre-release".to_string());
@@ -299,7 +299,7 @@ impl ExtensionSubcommand {
}
ExtensionSubcommand::Uninstall(args) => {
for id in args.id.iter() {
target.push(format!("--uninstall-extension={}", id));
target.push(format!("--uninstall-extension={id}"));
}
}
ExtensionSubcommand::Update => {
@@ -439,11 +439,11 @@ impl EditorOptions {
target.push("--wait".to_string());
}
if let Some(locale) = &self.locale {
target.push(format!("--locale={}", locale));
target.push(format!("--locale={locale}"));
}
if !self.enable_proposed_api.is_empty() {
for id in self.enable_proposed_api.iter() {
target.push(format!("--enable-proposed-api={}", id));
target.push(format!("--enable-proposed-api={id}"));
}
}
self.code_options.add_code_args(target);
@@ -480,10 +480,10 @@ pub struct OutputFormatOptions {
impl DesktopCodeOptions {
pub fn add_code_args(&self, target: &mut Vec<String>) {
if let Some(extensions_dir) = &self.extensions_dir {
target.push(format!("--extensions-dir={}", extensions_dir));
target.push(format!("--extensions-dir={extensions_dir}"));
}
if let Some(user_data_dir) = &self.user_data_dir {
target.push(format!("--user-data-dir={}", user_data_dir));
target.push(format!("--user-data-dir={user_data_dir}"));
}
}
}
@@ -522,13 +522,13 @@ impl GlobalOptions {
target.push("--verbose".to_string());
}
if let Some(log) = self.log {
target.push(format!("--log={}", log));
target.push(format!("--log={log}"));
}
if self.disable_telemetry {
target.push("--disable-telemetry".to_string());
}
if let Some(telemetry_level) = &self.telemetry_level {
target.push(format!("--telemetry-level={}", telemetry_level));
target.push(format!("--telemetry-level={telemetry_level}"));
}
}
}
@@ -578,16 +578,16 @@ impl EditorTroubleshooting {
target.push("--disable-extensions".to_string());
}
for id in self.disable_extension.iter() {
target.push(format!("--disable-extension={}", id));
target.push(format!("--disable-extension={id}"));
}
if let Some(sync) = &self.sync {
target.push(format!("--sync={}", sync));
target.push(format!("--sync={sync}"));
}
if let Some(port) = &self.inspect_extensions {
target.push(format!("--inspect-extensions={}", port));
target.push(format!("--inspect-extensions={port}"));
}
if let Some(port) = &self.inspect_brk_extensions {
target.push(format!("--inspect-brk-extensions={}", port));
target.push(format!("--inspect-brk-extensions={port}"));
}
if self.disable_gpu {
target.push("--disable-gpu".to_string());

View File

@@ -125,7 +125,7 @@ pub async fn serve_web(ctx: CommandContext, mut args: ServeWebArgs) -> Result<i3
};
let builder = Server::try_bind(&addr).map_err(CodeError::CouldNotListenOnInterface)?;
let mut listening = format!("Web UI available at http://{}", addr);
let mut listening = format!("Web UI available at http://{addr}");
if let Some(base) = args.server_base_path {
if !base.starts_with('/') {
listening.push('/');
@@ -133,7 +133,7 @@ pub async fn serve_web(ctx: CommandContext, mut args: ServeWebArgs) -> Result<i3
listening.push_str(&base);
}
if let Some(ct) = args.connection_token {
listening.push_str(&format!("?tkn={}", ct));
listening.push_str(&format!("?tkn={ct}"));
}
ctx.log.result(listening);
@@ -223,12 +223,9 @@ fn append_secret_headers(
let headers = res.headers_mut();
headers.append(
hyper::header::SET_COOKIE,
format!(
"{}={}{}; SameSite=Strict; Path=/",
PATH_COOKIE_NAME, base_path, SECRET_KEY_MINT_PATH,
)
.parse()
.unwrap(),
format!("{PATH_COOKIE_NAME}={base_path}{SECRET_KEY_MINT_PATH}; SameSite=Strict; Path=/",)
.parse()
.unwrap(),
);
headers.append(
hyper::header::SET_COOKIE,
@@ -445,14 +442,14 @@ mod response {
pub fn connection_err(err: hyper::Error) -> Response<Body> {
Response::builder()
.status(503)
.body(Body::from(format!("Error connecting to server: {:?}", err)))
.body(Body::from(format!("Error connecting to server: {err:?}")))
.unwrap()
}
pub fn code_err(err: CodeError) -> Response<Body> {
Response::builder()
.status(500)
.body(Body::from(format!("Error serving request: {}", err)))
.body(Body::from(format!("Error serving request: {err}")))
.unwrap()
}

View File

@@ -213,7 +213,7 @@ pub async fn command_shell(ctx: CommandContext, args: CommandShellArgs) -> Resul
match socket {
Ok((read, write)) => servers.push(serve_stream(read, write, params.clone())),
Err(e) => {
error!(params.log, &format!("Error accepting connection: {}", e));
error!(params.log, &format!("Error accepting connection: {e}"));
return Ok(1);
}
}
@@ -279,7 +279,7 @@ pub async fn service(
],
)
.await?;
ctx.log.result(format!("Service successfully installed! You can use `{} tunnel service log` to monitor it, and `{} tunnel service uninstall` to remove it.", APPLICATION_NAME, APPLICATION_NAME));
ctx.log.result(format!("Service successfully installed! You can use `{APPLICATION_NAME} tunnel service log` to monitor it, and `{APPLICATION_NAME} tunnel service uninstall` to remove it."));
}
TunnelServiceSubCommands::Uninstall => {
manager.unregister().await?;

View File

@@ -36,7 +36,7 @@ pub async fn update(ctx: CommandContext, args: StandaloneUpdateArgs) -> Result<i
if args.check {
ctx.log
.result(format!("Update to {} is available", current_version));
.result(format!("Update to {current_version} is available"));
return Ok(0);
}
@@ -46,7 +46,7 @@ pub async fn update(ctx: CommandContext, args: StandaloneUpdateArgs) -> Result<i
.do_update(&current_version, ProgressBarReporter::from(pb))
.await?;
ctx.log
.result(format!("Successfully updated to {}", current_version));
.result(format!("Successfully updated to {current_version}"));
Ok(0)
}

View File

@@ -48,7 +48,7 @@ pub async fn show(ctx: CommandContext) -> Result<i32, AnyError> {
let vm = CodeVersionManager::new(ctx.log.clone(), &ctx.paths, platform);
let version = vm.get_preferred_version();
println!("Current quality: {}", version);
println!("Current quality: {version}");
match vm.try_get_entrypoint(&version).await {
Some(p) => println!("Installation path: {}", p.display()),
None => println!("No existing installation found"),

View File

@@ -41,13 +41,13 @@ impl RequestedVersion {
pub fn get_command(&self) -> String {
match self {
RequestedVersion::Default => {
format!("code version use {}", QUALITY)
format!("code version use {QUALITY}")
}
RequestedVersion::Commit(commit) => {
format!("code version use {}/{}", QUALITY, commit)
format!("code version use {QUALITY}/{commit}")
}
RequestedVersion::Path(path) => {
format!("code version use {}", path)
format!("code version use {path}")
}
}
}
@@ -57,12 +57,12 @@ impl std::fmt::Display for RequestedVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
RequestedVersion::Default => {
write!(f, "{}", QUALITY)
write!(f, "{QUALITY}")
}
RequestedVersion::Commit(commit) => {
write!(f, "{}/{}", QUALITY, commit)
write!(f, "{QUALITY}/{commit}")
}
RequestedVersion::Path(path) => write!(f, "{}", path),
RequestedVersion::Path(path) => write!(f, "{path}"),
}
}
}
@@ -222,17 +222,14 @@ impl CodeVersionManager {
/// Shows a nice UI prompt to users asking them if they want to install the
/// requested version.
pub fn prompt_to_install(version: &RequestedVersion) {
println!(
"No installation of {} {} was found.",
QUALITYLESS_PRODUCT_NAME, version
);
println!("No installation of {QUALITYLESS_PRODUCT_NAME} {version} was found.");
if let RequestedVersion::Default = version {
if let Some(uri) = PRODUCT_DOWNLOAD_URL {
// todo: on some platforms, we may be able to help automate installation. For example,
// we can unzip the app ourselves on macOS and on windows we can download and spawn the GUI installer
#[cfg(target_os = "linux")]
println!("Install it from your system's package manager or {}, restart your shell, and try again.", uri);
println!("Install it from your system's package manager or {uri}, restart your shell, and try again.");
#[cfg(target_os = "macos")]
println!("Download and unzip it from {} and try again.", uri);
#[cfg(target_os = "windows")]
@@ -447,7 +444,7 @@ mod tests {
// developers can run this test and debug output manually; VS Code will not
// be installed in CI, so the test only makes sure it doesn't error out
let result = detect_installed_program(&log::Logger::test());
println!("result: {:?}", result);
println!("result: {result:?}");
assert!(result.is_ok());
}

View File

@@ -90,7 +90,7 @@ impl DownloadCache {
return Ok(target_dir);
}
let temp_dir = self.path.join(format!("{}{}", name, STAGING_SUFFIX));
let temp_dir = self.path.join(format!("{name}{STAGING_SUFFIX}"));
let _ = remove_dir_all(&temp_dir).await; // cleanup any existing
create_dir_all(&temp_dir).map_err(|e| wrap(e, "error creating server directory"))?;

View File

@@ -149,7 +149,7 @@ impl LogSink for StdioLogSink {
}
fn write_result(&self, message: &str) {
println!("{}", message);
println!("{message}");
}
}
@@ -214,7 +214,7 @@ impl Logger {
}
pub fn span(&self, name: &str) -> SpanBuilder {
self.tracer.span_builder(format!("serverlauncher/{}", name))
self.tracer.span_builder(format!("serverlauncher/{name}"))
}
pub fn tracer(&self) -> &Tracer {
@@ -237,8 +237,8 @@ impl Logger {
pub fn prefixed(&self, prefix: &str) -> Logger {
Logger {
prefix: Some(match &self.prefix {
Some(p) => format!("{}{} ", p, prefix),
None => format!("{} ", prefix),
Some(p) => format!("{p}{prefix} "),
None => format!("{prefix} "),
}),
..self.clone()
}
@@ -312,22 +312,19 @@ fn format(level: Level, prefix: &str, message: &str, use_colors: bool) -> String
if use_colors {
if let Some(c) = level.color_code() {
return format!(
"\x1b[2m[{}]\x1b[0m {}{}\x1b[0m {}{}\n",
timestamp, c, name, prefix, message
);
return format!("\x1b[2m[{timestamp}]\x1b[0m {c}{name}\x1b[0m {prefix}{message}\n");
}
}
format!("[{}] {} {}{}\n", timestamp, name, prefix, message)
format!("[{timestamp}] {name} {prefix}{message}\n")
}
pub fn emit(level: Level, prefix: &str, message: &str) {
let line = format(level, prefix, message, *COLORS_ENABLED);
if level == Level::Trace && *COLORS_ENABLED {
print!("\x1b[2m{}\x1b[0m", line);
print!("\x1b[2m{line}\x1b[0m");
} else {
print!("{}", line);
print!("{line}");
}
}

View File

@@ -70,8 +70,7 @@ impl TryFrom<&str> for Quality {
"insiders" | "insider" => Ok(Quality::Insiders),
"exploration" => Ok(Quality::Exploration),
_ => Err(format!(
"Unknown quality: {}. Must be one of stable, insiders, or exploration.",
s
"Unknown quality: {s}. Must be one of stable, insiders, or exploration."
)),
}
}

View File

@@ -105,7 +105,7 @@ impl<S: Serialization, C: Send + Sync + 'static> RpcMethodBuilder<S, C> {
F: Fn(P, &C) -> Result<R, AnyError> + Send + Sync + 'static,
{
if self.methods.contains_key(method_name) {
panic!("Method already registered: {}", method_name);
panic!("Method already registered: {method_name}");
}
let serial = self.serializer.clone();
@@ -121,7 +121,7 @@ impl<S: Serialization, C: Send + Sync + 'static> RpcMethodBuilder<S, C> {
id,
error: ResponseError {
code: 0,
message: format!("{:?}", err),
message: format!("{err:?}"),
},
})
})
@@ -135,7 +135,7 @@ impl<S: Serialization, C: Send + Sync + 'static> RpcMethodBuilder<S, C> {
id,
error: ResponseError {
code: -1,
message: format!("{:?}", err),
message: format!("{err:?}"),
},
})
}),
@@ -165,7 +165,7 @@ impl<S: Serialization, C: Send + Sync + 'static> RpcMethodBuilder<S, C> {
id,
error: ResponseError {
code: 0,
message: format!("{:?}", err),
message: format!("{err:?}"),
},
})
}))
@@ -186,7 +186,7 @@ impl<S: Serialization, C: Send + Sync + 'static> RpcMethodBuilder<S, C> {
id,
error: ResponseError {
code: -1,
message: format!("{:?}", err),
message: format!("{err:?}"),
},
})
}),
@@ -226,7 +226,7 @@ impl<S: Serialization, C: Send + Sync + 'static> RpcMethodBuilder<S, C> {
id,
error: ResponseError {
code: 0,
message: format!("{:?}", err),
message: format!("{err:?}"),
},
})
}))
@@ -259,7 +259,7 @@ impl<S: Serialization, C: Send + Sync + 'static> RpcMethodBuilder<S, C> {
id,
error: ResponseError {
code: -1,
message: format!("{:?}", err),
message: format!("{err:?}"),
},
})
}),
@@ -431,7 +431,7 @@ impl<S: Serialization, C: Send + Sync> RpcDispatcher<S, C> {
id,
error: ResponseError {
code: -1,
message: format!("Method not found: {}", method_name),
message: format!("Method not found: {method_name}"),
},
})
})),

View File

@@ -122,7 +122,7 @@ fn validate_cli_is_good(exe_path: &Path) -> Result<(), AnyError> {
let o = new_std_command(exe_path)
.args(["--version"])
.output()
.map_err(|e| CorruptDownload(format!("could not execute new binary, aborting: {}", e)))?;
.map_err(|e| CorruptDownload(format!("could not execute new binary, aborting: {e}")))?;
if !o.status.success() {
let msg = format!(

View File

@@ -155,17 +155,14 @@ impl LauncherPaths {
if let Err(e) = std::fs::rename(&old_dir, &new_dir) {
// no logger exists at this point in the lifecycle, so just log to stderr
eprintln!(
"Failed to migrate old CLI data directory, will create a new one ({})",
e
);
eprintln!("Failed to migrate old CLI data directory, will create a new one ({e})");
}
Self::new_for_path(new_dir)
}
pub fn new(root: Option<String>) -> Result<LauncherPaths, AnyError> {
let root = root.unwrap_or_else(|| format!("~/{}/cli", DEFAULT_DATA_PARENT_DIR));
let root = root.unwrap_or_else(|| format!("~/{DEFAULT_DATA_PARENT_DIR}/cli"));
let mut replaced = root.to_owned();
for token in HOME_DIR_ALTS {
if root.contains(token) {

View File

@@ -91,21 +91,21 @@ impl CodeServerArgs {
pub fn command_arguments(&self) -> Vec<String> {
let mut args = Vec::new();
if let Some(i) = &self.socket_path {
args.push(format!("--socket-path={}", i));
args.push(format!("--socket-path={i}"));
} else {
if let Some(i) = &self.host {
args.push(format!("--host={}", i));
args.push(format!("--host={i}"));
}
if let Some(i) = &self.port {
args.push(format!("--port={}", i));
args.push(format!("--port={i}"));
}
}
if let Some(i) = &self.connection_token {
args.push(format!("--connection-token={}", i));
args.push(format!("--connection-token={i}"));
}
if let Some(i) = &self.connection_token_file {
args.push(format!("--connection-token-file={}", i));
args.push(format!("--connection-token-file={i}"));
}
if self.without_connection_token {
args.push(String::from("--without-connection-token"));
@@ -114,14 +114,14 @@ impl CodeServerArgs {
args.push(String::from("--accept-server-license-terms"));
}
if let Some(i) = self.telemetry_level {
args.push(format!("--telemetry-level={}", i));
args.push(format!("--telemetry-level={i}"));
}
if let Some(i) = self.log {
args.push(format!("--log={}", i));
args.push(format!("--log={i}"));
}
for extension in &self.install_extensions {
args.push(format!("--install-extension={}", extension));
args.push(format!("--install-extension={extension}"));
}
if !&self.install_extensions.is_empty() {
if self.pre_release {
@@ -132,7 +132,7 @@ impl CodeServerArgs {
}
}
for extension in &self.uninstall_extensions {
args.push(format!("--uninstall-extension={}", extension));
args.push(format!("--uninstall-extension={extension}"));
}
if self.update_extensions {
args.push(String::from("--update-extensions"));
@@ -143,14 +143,14 @@ impl CodeServerArgs {
args.push(String::from("--show-versions"));
}
if let Some(i) = &self.category {
args.push(format!("--category={}", i));
args.push(format!("--category={i}"));
}
}
if let Some(d) = &self.server_data_dir {
args.push(format!("--server-data-dir={}", d));
args.push(format!("--server-data-dir={d}"));
}
if let Some(d) = &self.extensions_dir {
args.push(format!("--extensions-dir={}", d));
args.push(format!("--extensions-dir={d}"));
}
if self.start_server {
args.push(String::from("--start-server"));
@@ -487,7 +487,7 @@ impl<'a> ServerBuilder<'a> {
let mut cmd = self.get_base_command();
cmd.arg("--start-server")
.arg("--enable-remote-auto-shutdown")
.arg(format!("--port={}", port));
.arg(format!("--port={port}"));
let child = self.spawn_server_process(cmd).await?;
let log_file = self.get_logfile()?;
@@ -503,7 +503,7 @@ impl<'a> ServerBuilder<'a> {
}
Ok(Err(s)) => {
origin.kill().await;
return Err(CodeError::ServerUnexpectedExit(format!("{}", s)).into());
return Err(CodeError::ServerUnexpectedExit(format!("{s}")).into());
}
Ok(Ok(p)) => p,
};
@@ -577,7 +577,7 @@ impl<'a> ServerBuilder<'a> {
}
Ok(Err(s)) => {
origin.kill().await;
return Err(CodeError::ServerUnexpectedExit(format!("{}", s)).into());
return Err(CodeError::ServerUnexpectedExit(format!("{s}")).into());
}
Ok(Ok(socket)) => socket,
};
@@ -616,7 +616,7 @@ impl<'a> ServerBuilder<'a> {
.stderr(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.spawn()
.map_err(|e| CodeError::ServerUnexpectedExit(format!("{}", e)))?;
.map_err(|e| CodeError::ServerUnexpectedExit(format!("{e}")))?;
self.server_paths
.write_pid(child.id().expect("expected server to have pid"))?;
@@ -677,7 +677,7 @@ where
f.write_all(b"\n")?;
}
if write_directly {
println!("{}", line);
println!("{line}");
} else {
trace!(plog, line);
}
@@ -732,7 +732,7 @@ where
}
fn get_extensions_flag(extension_id: &str) -> String {
format!("--install-extension={}", extension_id)
format!("--install-extension={extension_id}")
}
/// A type that can be used to scan stdout from the VS Code server. Returns
@@ -829,7 +829,7 @@ pub fn print_listening(log: &log::Logger, tunnel_name: &str) {
}
}
let message = &format!("\nOpen this link in your browser {}\n", addr);
let message = &format!("\nOpen this link in your browser {addr}\n");
log.result(message);
}

View File

@@ -566,7 +566,7 @@ async fn process_socket(
{
debug!(log, "closing socket reader: {}", e);
socket_tx
.send(SocketSignal::CloseWith(CloseReason(format!("{}", e))))
.send(SocketSignal::CloseWith(CloseReason(format!("{e}"))))
.await
.ok();
}
@@ -1192,7 +1192,7 @@ async fn handle_acquire_cli(
let release = match params.commit_id {
Some(commit) => Release {
name: format!("{} CLI", PRODUCT_NAME_LONG),
name: format!("{PRODUCT_NAME_LONG} CLI"),
commit,
platform: params.platform,
quality: params.quality,

View File

@@ -65,7 +65,7 @@ mod tunnel_flags {
flags |= IS_WSL_INSTALLED;
}
format!("_flag{}", flags)
format!("_flag{flags}")
}
}
@@ -282,8 +282,7 @@ fn get_host_token_from_tunnel(tunnel: &Tunnel) -> String {
fn is_valid_name(name: &str) -> Result<(), InvalidTunnelName> {
if name.len() > MAX_TUNNEL_NAME_LENGTH {
return Err(InvalidTunnelName(format!(
"Names cannot be longer than {} characters. Please try a different name.",
MAX_TUNNEL_NAME_LENGTH
"Names cannot be longer than {MAX_TUNNEL_NAME_LENGTH} characters. Please try a different name."
)));
}
@@ -617,7 +616,7 @@ impl DevTunnels {
Err(e) => {
return Err(AnyError::from(TunnelCreationFailed(
name.to_string(),
format!("{:?}", e),
format!("{e:?}"),
)))
}
Ok(t) => break t,
@@ -789,7 +788,7 @@ impl DevTunnels {
let mut placeholder_name = Self::get_placeholder_name();
if !is_name_free(&placeholder_name) {
for i in 2.. {
let fixed_name = format!("{}{}", placeholder_name, i);
let fixed_name = format!("{placeholder_name}{i}");
if is_name_free(&fixed_name) {
placeholder_name = fixed_name;
break;

View File

@@ -64,8 +64,7 @@ impl SleepInhibitor {
return Err(wrap(
e2,
format!(
"error requesting sleep inhibition, pminhibitor gave {}, screensaver gave",
e1
"error requesting sleep inhibition, pminhibitor gave {e1}, screensaver gave"
),
)
.into());

View File

@@ -64,7 +64,7 @@ impl ServerPaths {
// VS Code Server pid
pub fn write_pid(&self, pid: u32) -> Result<(), WrappedError> {
write(&self.pidfile, format!("{}", pid)).map_err(|e| {
write(&self.pidfile, format!("{pid}")).map_err(|e| {
wrap(
e,
format!("error writing process id into {}", self.pidfile.display()),
@@ -155,5 +155,5 @@ pub fn get_all_servers(lp: &LauncherPaths) -> Vec<InstalledServer> {
}
pub fn get_server_folder_name(quality: Quality, commit: &str) -> String {
format!("{}-{}", quality, commit)
format!("{quality}-{commit}")
}

View File

@@ -85,7 +85,7 @@ pub(crate) async fn tail_log_file(log_file: &Path) -> Result<(), AnyError> {
let mut rx = tailf(file, 20);
while let Some(line) = rx.recv().await {
match line {
TailEvent::Line(l) => print!("{}", l),
TailEvent::Line(l) => print!("{l}"),
TailEvent::Reset => println!("== Tunnel service restarted =="),
TailEvent::Err(e) => return Err(wrap(e, "error reading log file").into()),
}

View File

@@ -62,7 +62,7 @@ impl SystemdService {
}
fn service_name_string() -> String {
format!("{}-tunnel.service", APPLICATION_NAME)
format!("{APPLICATION_NAME}-tunnel.service")
}
}

View File

@@ -28,7 +28,7 @@ impl fmt::Display for ShutdownSignal {
match self {
ShutdownSignal::CtrlC => write!(f, "Ctrl-C received"),
ShutdownSignal::ParentProcessKilled(p) => {
write!(f, "Parent process {} no longer exists", p)
write!(f, "Parent process {p} no longer exists")
}
ShutdownSignal::ExeUninstalled => {
write!(f, "Executable no longer exists")

View File

@@ -239,7 +239,8 @@ impl BroadcastLogSink {
fn replay_and_subscribe(
&self,
) -> ConcatReceivable<Vec<u8>, mpsc::UnboundedReceiver<Vec<u8>>, broadcast::Receiver<Vec<u8>>> {
) -> ConcatReceivable<Vec<u8>, mpsc::UnboundedReceiver<Vec<u8>>, broadcast::Receiver<Vec<u8>>>
{
let (log_replay_tx, log_replay_rx) = mpsc::unbounded_channel();
for log in self.recent.lock().unwrap().iter() {

View File

@@ -146,7 +146,7 @@ pub async fn kill_tree(process_id: u32) -> Result<(), CodeError> {
.stdout(Stdio::piped())
.spawn()
.map_err(|e| CodeError::CommandFailed {
command: format!("pgrep -P {}", parent_id),
command: format!("pgrep -P {parent_id}"),
code: -1,
output: e.to_string(),
})?;

View File

@@ -41,7 +41,7 @@ impl From<reqwest::Error> for WrappedError {
"error requesting {}",
e.url().map_or("<unknown>", |u| u.as_str())
),
original: format!("{}", e),
original: format!("{e}"),
}
}
}
@@ -53,7 +53,7 @@ where
{
WrappedError {
message: message.into(),
original: format!("{:?}", original),
original: format!("{original:?}"),
}
}
@@ -64,7 +64,7 @@ where
{
WrappedError {
message: message.into(),
original: format!("{}", original),
original: format!("{original}"),
}
}
@@ -93,10 +93,7 @@ impl StatusError {
let body = res.text().await.map_err(|e| {
wrap(
e,
format!(
"failed to read response body on {} code from {}",
status_code, url
),
format!("failed to read response body on {status_code} code from {url}"),
)
})?;
@@ -290,7 +287,7 @@ pub struct CannotForwardControlPort();
impl std::fmt::Display for CannotForwardControlPort {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Cannot forward or unforward port {}.", CONTROL_PORT)
write!(f, "Cannot forward or unforward port {CONTROL_PORT}.")
}
}
@@ -308,7 +305,7 @@ pub struct ServiceAlreadyRegistered();
impl std::fmt::Display for ServiceAlreadyRegistered {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Already registered the service. Run `{} tunnel service uninstall` to unregister it first", APPLICATION_NAME)
write!(f, "Already registered the service. Run `{APPLICATION_NAME} tunnel service uninstall` to unregister it first")
}
}
@@ -434,7 +431,7 @@ impl Display for DbusConnectFailedError {
str.push_str(&self.0);
str.push('\n');
write!(f, "{}", str)
write!(f, "{str}")
}
}

View File

@@ -313,7 +313,7 @@ mod tests {
let base_line = "Elit ipsum cillum ex cillum. Adipisicing consequat cupidatat do proident ut in sunt Lorem ipsum tempor. Eiusmod ipsum Lorem labore exercitation sunt pariatur excepteur fugiat cillum velit cillum enim. Nisi Lorem cupidatat ad enim velit officia eiusmod esse tempor aliquip. Deserunt pariatur tempor in duis culpa esse sit nulla irure ullamco ipsum voluptate non laboris. Occaecat officia nulla officia mollit do aliquip reprehenderit ad incididunt.";
for i in 0..100 {
let line = format!("{}: {}", i, &base_line[..rng.gen_range(0..base_line.len())]);
writeln!(&mut read_file, "{}", line).unwrap();
writeln!(&mut read_file, "{line}").unwrap();
written.push(line);
}
write!(&mut read_file, "partial line").unwrap();

View File

@@ -121,7 +121,7 @@ impl PreReqChecker {
let bullets = errors
.iter()
.map(|e| format!(" - {}", e))
.map(|e| format!(" - {e}"))
.collect::<Vec<String>>()
.join("\n");
@@ -142,8 +142,7 @@ async fn check_musl_interpreter() -> Result<(), String> {
if fs::metadata(MUSL_PATH).await.is_err() {
return Err(format!(
"find {}, which is required to run the {} in musl environments",
MUSL_PATH, QUALITYLESS_SERVER_NAME
"find {MUSL_PATH}, which is required to run the {QUALITYLESS_SERVER_NAME} in musl environments"
));
}
@@ -231,8 +230,7 @@ async fn check_glibcxx_version() -> Result<bool, String> {
Some(path) => match fs::read(&path).await {
Ok(contents) => check_for_sufficient_glibcxx_versions(contents),
Err(e) => Err(format!(
"validate GLIBCXX version for GNU environments, but could not: {}",
e
"validate GLIBCXX version for GNU environments, but could not: {e}"
)),
},
None => Err("find libstdc++.so or ldconfig for GNU environments".to_owned()),

View File

@@ -60,7 +60,7 @@ where
}
let mut file = archive
.by_index(i)
.map_err(|e| wrap(e, format!("could not open zip entry {}", i)))?;
.map_err(|e| wrap(e, format!("could not open zip entry {i}")))?;
let outpath: PathBuf = match file.enclosed_name() {
Some(path) => {