Fix formatting issues

This commit is contained in:
Chip Senkbeil 2023-03-30 18:31:16 -05:00
parent 78b0ee628e
commit 5940b21339
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131
25 changed files with 55 additions and 61 deletions

View File

@ -54,7 +54,7 @@ impl DistantApiServerHandler<LocalDistantApi, <LocalDistantApi as DistantApi>::L
fn unsupported<T>(label: &str) -> io::Result<T> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
format!("{} is unsupported", label),
format!("{label} is unsupported"),
))
}

View File

@ -243,7 +243,7 @@ async fn watcher_task(mut watcher: impl Watcher, mut rx: mpsc::Receiver<InnerWat
// Send a failure as there was nothing to unwatch for this connection
let _ = cb.send(Err(io::Error::new(
io::ErrorKind::Other,
format!("{:?} is not being watched", path),
format!("{path:?} is not being watched"),
)));
} else {
// Send a success as we removed some paths
@ -253,7 +253,7 @@ async fn watcher_task(mut watcher: impl Watcher, mut rx: mpsc::Receiver<InnerWat
// Send a failure as there was nothing to unwatch
let _ = cb.send(Err(io::Error::new(
io::ErrorKind::Other,
format!("{:?} is not being watched", path),
format!("{path:?} is not being watched"),
)));
}
}

View File

@ -174,7 +174,7 @@ impl RegisteredPath {
.send(if paths.is_empty() {
DistantResponseData::Error(Error::from(msg))
} else {
DistantResponseData::Error(Error::from(format!("{} about {:?}", msg, paths)))
DistantResponseData::Error(Error::from(format!("{msg} about {paths:?}")))
})
.await
.map(|_| true)

View File

@ -208,7 +208,7 @@ impl fmt::Display for LspHeader {
write!(f, "Content-Length: {}\r\n", self.content_length)?;
if let Some(ty) = self.content_type.as_ref() {
write!(f, "Content-Type: {}\r\n", ty)?;
write!(f, "Content-Type: {ty}\r\n")?;
}
write!(f, "\r\n")

View File

@ -67,7 +67,7 @@ impl Searcher {
x => {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Unexpected response: {:?}", x),
format!("Unexpected response: {x:?}"),
))
}
}

View File

@ -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:?}"),
))
}
}

View File

@ -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)?;

View File

@ -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<walkdir::Error> for Error {
} else {
Self {
kind: ErrorKind::Loop,
description: format!("{}", x),
description: format!("{x}"),
}
}
}
@ -117,7 +117,7 @@ impl From<tokio::task::JoinError> for Error {
} else {
ErrorKind::TaskPanicked
},
description: format!("{}", x),
description: format!("{x}"),
}
}
}

View File

@ -8,8 +8,7 @@ where
Some(s) => match s.parse::<u128>() {
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),

View File

@ -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

View File

@ -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,

View File

@ -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 {

View File

@ -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")]

View File

@ -10,7 +10,7 @@ pub fn serialize_to_vec<T: Serialize>(value: &T) -> io::Result<Vec<u8>> {
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<T: DeserializeOwned>(slice: &[u8]) -> io::Result<T
rmp_serde::decode::from_slice(slice).map_err(|x| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Deserialize failed: {}", x),
format!("Deserialize failed: {x}"),
)
})
}

View File

@ -109,7 +109,7 @@ impl ManagerClient {
x => {
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:?}"),
)),
}
}

View File

@ -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

View File

@ -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")]

View File

@ -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<bool> {
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::<Vec<IpAddr>>();
candidate_ips.sort_unstable();

View File

@ -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::<PtySize>(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;
}

View File

@ -81,7 +81,7 @@ impl<T: AuthHandler + Clone> Client<T> {
}
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 {

View File

@ -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(),
}
);

View File

@ -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 {

View File

@ -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 {

View File

@ -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::<Vec<IpAddr>>();
candidate_ips.sort_unstable();

View File

@ -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()