From 5940b21339663afad3eaacbafa1d7c9cec1c632e Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Thu, 30 Mar 2023 18:31:16 -0500 Subject: [PATCH] Fix formatting issues --- distant-core/src/api.rs | 2 +- distant-core/src/api/local/state/watcher.rs | 4 ++-- .../src/api/local/state/watcher/path.rs | 2 +- distant-core/src/client/lsp/msg.rs | 2 +- distant-core/src/client/searcher.rs | 2 +- distant-core/src/client/watcher.rs | 6 +++--- distant-core/src/credentials.rs | 2 +- distant-core/src/data/error.rs | 6 +++--- distant-core/src/data/utils.rs | 3 +-- .../authentication/handler/methods/prompt.rs | 2 +- distant-net/src/common/authentication/msg.rs | 2 +- distant-net/src/common/destination.rs | 4 ++-- distant-net/src/common/map.rs | 4 ++-- distant-net/src/common/utils.rs | 4 ++-- distant-net/src/manager/client.rs | 12 ++++++------ distant-net/src/manager/server.rs | 4 ++-- distant-net/src/server/config.rs | 4 ++-- distant-ssh2/src/lib.rs | 7 +++---- distant-ssh2/src/process.rs | 19 ++++++++----------- src/cli/client.rs | 2 +- src/cli/commands/client.rs | 8 ++++---- src/cli/commands/client/format.rs | 6 +++--- src/cli/commands/manager.rs | 2 +- src/cli/commands/manager/handlers.rs | 1 - src/cli/commands/server.rs | 6 +++--- 25 files changed, 55 insertions(+), 61 deletions(-) diff --git a/distant-core/src/api.rs b/distant-core/src/api.rs index 7d90120..9f9e1c8 100644 --- a/distant-core/src/api.rs +++ b/distant-core/src/api.rs @@ -54,7 +54,7 @@ impl DistantApiServerHandler::L fn unsupported(label: &str) -> io::Result { Err(io::Error::new( io::ErrorKind::Unsupported, - format!("{} is unsupported", label), + format!("{label} is unsupported"), )) } diff --git a/distant-core/src/api/local/state/watcher.rs b/distant-core/src/api/local/state/watcher.rs index 18f2133..b50aabe 100644 --- a/distant-core/src/api/local/state/watcher.rs +++ b/distant-core/src/api/local/state/watcher.rs @@ -243,7 +243,7 @@ async fn watcher_task(mut watcher: impl Watcher, mut rx: mpsc::Receiver { return Err(io::Error::new( io::ErrorKind::Other, - format!("Unexpected response: {:?}", x), + format!("Unexpected response: {x:?}"), )) } } diff --git a/distant-core/src/client/watcher.rs b/distant-core/src/client/watcher.rs index cb366bd..3760fe1 100644 --- a/distant-core/src/client/watcher.rs +++ b/distant-core/src/client/watcher.rs @@ -46,12 +46,12 @@ impl Watcher { if only.is_empty() { String::new() } else { - format!(" (only = {})", only) + format!(" (only = {only})") }, if except.is_empty() { String::new() } else { - format!(" (except = {})", except) + format!(" (except = {except})") }, ); @@ -83,7 +83,7 @@ impl Watcher { x => { return Err(io::Error::new( io::ErrorKind::Other, - format!("Unexpected response: {:?}", x), + format!("Unexpected response: {x:?}"), )) } } diff --git a/distant-core/src/credentials.rs b/distant-core/src/credentials.rs index 59360f9..0fd4455 100644 --- a/distant-core/src/credentials.rs +++ b/distant-core/src/credentials.rs @@ -22,7 +22,7 @@ impl fmt::Display for DistantSingleKeyCredentials { write!(f, "{SCHEME}://")?; if let Some(username) = self.username.as_ref() { - write!(f, "{}", username)?; + write!(f, "{username}")?; } write!(f, ":{}@", self.key)?; diff --git a/distant-core/src/data/error.rs b/distant-core/src/data/error.rs index 406d02a..f9e5807 100644 --- a/distant-core/src/data/error.rs +++ b/distant-core/src/data/error.rs @@ -6,7 +6,7 @@ use std::io; /// General purpose error type that can be sent across the wire #[derive(Clone, Debug, Display, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[display(fmt = "{}: {}", kind, description)] +#[display(fmt = "{kind}: {description}")] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Error { /// Label describing the kind of error @@ -103,7 +103,7 @@ impl From for Error { } else { Self { kind: ErrorKind::Loop, - description: format!("{}", x), + description: format!("{x}"), } } } @@ -117,7 +117,7 @@ impl From for Error { } else { ErrorKind::TaskPanicked }, - description: format!("{}", x), + description: format!("{x}"), } } } diff --git a/distant-core/src/data/utils.rs b/distant-core/src/data/utils.rs index ceec131..e98e278 100644 --- a/distant-core/src/data/utils.rs +++ b/distant-core/src/data/utils.rs @@ -8,8 +8,7 @@ where Some(s) => match s.parse::() { Ok(value) => Ok(Some(value)), Err(error) => Err(serde::de::Error::custom(format!( - "Cannot convert to u128 with error: {:?}", - error + "Cannot convert to u128 with error: {error:?}" ))), }, None => Ok(None), diff --git a/distant-net/src/common/authentication/handler/methods/prompt.rs b/distant-net/src/common/authentication/handler/methods/prompt.rs index 8d6ab53..901a8aa 100644 --- a/distant-net/src/common/authentication/handler/methods/prompt.rs +++ b/distant-net/src/common/authentication/handler/methods/prompt.rs @@ -40,7 +40,7 @@ where // Go ahead and display all other lines for line in lines.into_iter() { - eprintln!("{}", line); + eprintln!("{line}"); } // Get an answer from user input, or use a blank string as an answer diff --git a/distant-net/src/common/authentication/msg.rs b/distant-net/src/common/authentication/msg.rs index ef6baf6..39e38c0 100644 --- a/distant-net/src/common/authentication/msg.rs +++ b/distant-net/src/common/authentication/msg.rs @@ -158,7 +158,7 @@ impl Question { /// Represents some error that occurred during authentication #[derive(Clone, Debug, Display, Error, PartialEq, Eq, Serialize, Deserialize)] -#[display(fmt = "{}: {}", kind, text)] +#[display(fmt = "{kind}: {text}")] pub struct Error { /// Represents the kind of error pub kind: ErrorKind, diff --git a/distant-net/src/common/destination.rs b/distant-net/src/common/destination.rs index af01179..1bf3a05 100644 --- a/distant-net/src/common/destination.rs +++ b/distant-net/src/common/destination.rs @@ -79,8 +79,8 @@ impl fmt::Display for Destination { // For host, if we have a port and are IPv6, we need to wrap in [{}] match &self.host { - Host::Ipv6(x) if self.port.is_some() => write!(f, "[{}]", x)?, - x => write!(f, "{}", x)?, + Host::Ipv6(x) if self.port.is_some() => write!(f, "[{x}]")?, + x => write!(f, "{x}")?, } if let Some(port) = self.port { diff --git a/distant-net/src/common/map.rs b/distant-net/src/common/map.rs index 8410588..98811e1 100644 --- a/distant-net/src/common/map.rs +++ b/distant-net/src/common/map.rs @@ -68,10 +68,10 @@ impl fmt::Display for Map { #[derive(Clone, Debug, Display, Error)] pub enum MapParseError { - #[display(fmt = "Missing = after key ('{}')", key)] + #[display(fmt = "Missing = after key ('{key}')")] MissingEqualsAfterKey { key: String }, - #[display(fmt = "Key ('{}') must start with alphabetic character", key)] + #[display(fmt = "Key ('{key}') must start with alphabetic character")] KeyMustStartWithAlphabeticCharacter { key: String }, #[display(fmt = "Missing closing \" for value")] diff --git a/distant-net/src/common/utils.rs b/distant-net/src/common/utils.rs index 413a1b8..be5ee0d 100644 --- a/distant-net/src/common/utils.rs +++ b/distant-net/src/common/utils.rs @@ -10,7 +10,7 @@ pub fn serialize_to_vec(value: &T) -> io::Result> { rmp_serde::encode::to_vec_named(value).map_err(|x| { io::Error::new( io::ErrorKind::InvalidData, - format!("Serialize failed: {}", x), + format!("Serialize failed: {x}"), ) }) } @@ -19,7 +19,7 @@ pub fn deserialize_from_slice(slice: &[u8]) -> io::Result { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Got unexpected response: {:?}", x), + format!("Got unexpected response: {x:?}"), )) } } @@ -208,7 +208,7 @@ impl ManagerClient { x => { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Got unexpected response: {:?}", x), + format!("Got unexpected response: {x:?}"), )) } } @@ -246,7 +246,7 @@ impl ManagerClient { } x => Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Got unexpected response: {:?}", x), + format!("Got unexpected response: {x:?}"), )), } } @@ -262,7 +262,7 @@ impl ManagerClient { } x => Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Got unexpected response: {:?}", x), + format!("Got unexpected response: {x:?}"), )), } } @@ -278,7 +278,7 @@ impl ManagerClient { } x => Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Got unexpected response: {:?}", x), + format!("Got unexpected response: {x:?}"), )), } } @@ -294,7 +294,7 @@ impl ManagerClient { } x => Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Got unexpected response: {:?}", x), + format!("Got unexpected response: {x:?}"), )), } } diff --git a/distant-net/src/manager/server.rs b/distant-net/src/manager/server.rs index e2f3658..ab1cd1c 100644 --- a/distant-net/src/manager/server.rs +++ b/distant-net/src/manager/server.rs @@ -77,7 +77,7 @@ impl ManagerServer { let handler = self.config.launch_handlers.get(&scheme).ok_or_else(|| { io::Error::new( io::ErrorKind::InvalidInput, - format!("No launch handler registered for {}", scheme), + format!("No launch handler registered for {scheme}"), ) })?; handler @@ -116,7 +116,7 @@ impl ManagerServer { let handler = self.config.connect_handlers.get(&scheme).ok_or_else(|| { io::Error::new( io::ErrorKind::InvalidInput, - format!("No connect handler registered for {}", scheme), + format!("No connect handler registered for {scheme}"), ) })?; handler diff --git a/distant-net/src/server/config.rs b/distant-net/src/server/config.rs index 501abaf..2fac22b 100644 --- a/distant-net/src/server/config.rs +++ b/distant-net/src/server/config.rs @@ -64,10 +64,10 @@ impl Default for Shutdown { /// Parsing errors that can occur for [`Shutdown`] #[derive(Clone, Debug, Display, Error, PartialEq, Eq)] pub enum ShutdownParseError { - #[display(fmt = "Bad value for after: {}", _0)] + #[display(fmt = "Bad value for after: {_0}")] BadValueForAfter(ParseFloatError), - #[display(fmt = "Bad value for lonely: {}", _0)] + #[display(fmt = "Bad value for lonely: {_0}")] BadValueForLonely(ParseFloatError), #[display(fmt = "Missing key")] diff --git a/distant-ssh2/src/lib.rs b/distant-ssh2/src/lib.rs index 2ffd5c8..708d9cd 100644 --- a/distant-ssh2/src/lib.rs +++ b/distant-ssh2/src/lib.rs @@ -271,11 +271,11 @@ impl SshAuthHandler for LocalSshAuthHandler { // Go ahead and display all other lines for line in prompt_lines.into_iter() { - eprintln!("{}", line); + eprintln!("{line}"); } let answer = if prompt.echo { - eprint!("{}", prompt_line); + eprint!("{prompt_line}"); std::io::stderr().lock().flush()?; let mut answer = String::new(); @@ -296,7 +296,7 @@ impl SshAuthHandler for LocalSshAuthHandler { async fn on_verify_host(&self, host: &str) -> io::Result { trace!("[local] on_verify_host({host})"); - eprintln!("{}", host); + eprintln!("{host}"); let task = tokio::task::spawn_blocking(|| { eprint!("Enter [y/N]> "); std::io::stderr().lock().flush()?; @@ -556,7 +556,6 @@ impl Ssh { format!("{} needs to be resolvable outside of ssh: {}", self.host, x), ) })? - .into_iter() .map(|addr| addr.ip()) .collect::>(); candidate_ips.sort_unstable(); diff --git a/distant-ssh2/src/process.rs b/distant-ssh2/src/process.rs index 6a0a465..07b182d 100644 --- a/distant-ssh2/src/process.rs +++ b/distant-ssh2/src/process.rs @@ -76,7 +76,7 @@ where if let Ok(Some(exit_status)) = child.try_wait() { return Err(io::Error::new( io::ErrorKind::BrokenPipe, - format!("Process exited early: {:?}", exit_status), + format!("Process exited early: {exit_status:?}"), )); } @@ -88,7 +88,7 @@ where let stdout_task = spawn_nonblocking_stdout_task(id, stdout, reply.clone_reply()); let stderr_task = spawn_nonblocking_stderr_task(id, stderr, reply.clone_reply()); let stdin_task = spawn_nonblocking_stdin_task(id, stdin, stdin_rx); - let _ = spawn_cleanup_task( + drop(spawn_cleanup_task( session, id, child, @@ -98,7 +98,7 @@ where Some(stderr_task), reply, cleanup, - ); + )); // Create a resizer that is already closed since a simple process does not resize let resizer = mpsc::channel(1).0; @@ -157,7 +157,7 @@ where if let Ok(Some(exit_status)) = child.try_wait() { return Err(io::Error::new( io::ErrorKind::BrokenPipe, - format!("Process exited early: {:?}", exit_status), + format!("Process exited early: {exit_status:?}"), )); } @@ -175,7 +175,7 @@ where let session = session.clone(); let stdout_task = spawn_blocking_stdout_task(id, reader, reply.clone_reply()); let stdin_task = spawn_blocking_stdin_task(id, writer, stdin_rx); - let _ = spawn_cleanup_task( + drop(spawn_cleanup_task( session, id, child, @@ -185,7 +185,7 @@ where None, reply, cleanup, - ); + )); let (resize_tx, mut resize_rx) = mpsc::channel::(1); tokio::spawn(async move { @@ -391,12 +391,9 @@ where // so, we need to manually run kill/taskkill to make sure that the // process is sent a kill signal if let Some(pid) = child.process_id() { + let _ = session.exec(&format!("kill -9 {pid}"), None).compat().await; let _ = session - .exec(&format!("kill -9 {}", pid), None) - .compat() - .await; - let _ = session - .exec(&format!("taskkill /F /PID {}", pid), None) + .exec(&format!("taskkill /F /PID {pid}"), None) .compat() .await; } diff --git a/src/cli/client.rs b/src/cli/client.rs index 35c7fb0..92812ed 100644 --- a/src/cli/client.rs +++ b/src/cli/client.rs @@ -81,7 +81,7 @@ impl Client { } Err(x) => { let err = anyhow::Error::new(x) - .context(format!("Failed to connect to unix socket {:?}", path)); + .context(format!("Failed to connect to unix socket {path:?}")); if let Some(x) = error { error = Some(x.context(err)); } else { diff --git a/src/cli/commands/client.rs b/src/cli/commands/client.rs index 7663ced..d0cd895 100644 --- a/src/cli/commands/client.rs +++ b/src/cli/commands/client.rs @@ -279,7 +279,7 @@ impl ClientSubcommand { debug!( "Timeout configured to be {}", match timeout { - Some(secs) => format!("{}s", secs), + Some(secs) => format!("{secs}s"), None => "none".to_string(), } ); @@ -452,7 +452,7 @@ impl ClientSubcommand { cache.write_to_disk().await?; match format { - Format::Shell => println!("{}", id), + Format::Shell => println!("{id}"), Format::Json => println!( "{}", serde_json::to_string(&json!({ @@ -550,7 +550,7 @@ impl ClientSubcommand { cache.write_to_disk().await?; match format { - Format::Shell => println!("{}", id), + Format::Shell => println!("{id}"), Format::Json => println!( "{}", serde_json::to_string(&json!({ @@ -632,7 +632,7 @@ impl ClientSubcommand { debug!( "Timeout configured to be {}", match timeout { - Some(secs) => format!("{}s", secs), + Some(secs) => format!("{secs}s"), None => "none".to_string(), } ); diff --git a/src/cli/commands/client/format.rs b/src/cli/commands/client/format.rs index 07daabb..7680f88 100644 --- a/src/cli/commands/client/format.rs +++ b/src/cli/commands/client/format.rs @@ -227,7 +227,7 @@ fn format_shell(state: &mut FormatterState, data: DistantResponseData) -> Output "{}", ), canonicalized_path - .map(|p| format!("Canonicalized Path: {:?}\n", p)) + .map(|p| format!("Canonicalized Path: {p:?}\n")) .unwrap_or_default(), file_type.as_ref(), len, @@ -371,9 +371,9 @@ fn format_shell(state: &mut FormatterState, data: DistantResponseData) -> Output if success { Output::None } else if let Some(code) = code { - Output::StderrLine(format!("Proc {} failed with code {}", id, code).into_bytes()) + Output::StderrLine(format!("Proc {id} failed with code {code}").into_bytes()) } else { - Output::StderrLine(format!("Proc {} failed", id).into_bytes()) + Output::StderrLine(format!("Proc {id} failed").into_bytes()) } } DistantResponseData::SystemInfo(SystemInfo { diff --git a/src/cli/commands/manager.rs b/src/cli/commands/manager.rs index 160e1fb..d2946d4 100644 --- a/src/cli/commands/manager.rs +++ b/src/cli/commands/manager.rs @@ -168,7 +168,7 @@ impl ManagerSubcommand { Ok(()) } Ok(Fork::Parent(pid)) => { - println!("[distant manager detached, pid = {}]", pid); + println!("[distant manager detached, pid = {pid}]"); if fork::close_fd().is_err() { Err(CliError::Error(anyhow::anyhow!("Fork failed to close fd"))) } else { diff --git a/src/cli/commands/manager/handlers.rs b/src/cli/commands/manager/handlers.rs index fd1a972..9791941 100644 --- a/src/cli/commands/manager/handlers.rs +++ b/src/cli/commands/manager/handlers.rs @@ -254,7 +254,6 @@ impl ConnectHandler for DistantConnectHandler { format!("{host} needs to be resolvable outside of ssh: {x}"), ) })? - .into_iter() .map(|addr| addr.ip()) .collect::>(); candidate_ips.sort_unstable(); diff --git a/src/cli/commands/server.rs b/src/cli/commands/server.rs index bca69c6..c21fbba 100644 --- a/src/cli/commands/server.rs +++ b/src/cli/commands/server.rs @@ -107,7 +107,7 @@ impl ServerSubcommand { Ok(()) } Ok(Fork::Parent(pid)) => { - println!("[distant server detached, pid = {}]", pid); + println!("[distant server detached, pid = {pid}]"); if fork::close_fd().is_err() { Err(CliError::Error(anyhow::anyhow!("Fork failed to close fd"))) } else { @@ -163,7 +163,7 @@ impl ServerSubcommand { "Starting local API server, binding to {} {}", addr, match get!(port) { - Some(range) => format!("with port in range {}", range), + Some(range) => format!("with port in range {range}"), None => "using an ephemeral port".to_string(), } ); @@ -204,7 +204,7 @@ impl ServerSubcommand { #[cfg(not(windows))] { println!("\r"); - println!("{}", credentials); + println!("{credentials}"); println!("\r"); io::stdout() .flush()