mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-17 05:00:26 +00:00
Use captured identifiers in format strings (#507)
Makes for arguably cleaner-looking code. The downside is that the MSRV is 1.58 https://blog.rust-lang.org/2022/01/13/Rust-1.58.0.html Given that nobody uses lychee as a library yet and we have precompiled binaries, it's an acceptable tradeoff. My little research revealed that this is a much-liked feature: https://twitter.com/matthiasendler/status/1483895557621960715
This commit is contained in:
parent
53c41b03d8
commit
47df7780fe
13 changed files with 22 additions and 18 deletions
|
|
@ -291,7 +291,7 @@ use lychee_lib::Result;
|
|||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let response = lychee_lib::check("https://github.com/lycheeverse/lychee").await?;
|
||||
println!("{}", response);
|
||||
println!("{response}");
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ async fn main() -> Result<()> {
|
|||
|
||||
// Finally, listen to incoming responses from lychee
|
||||
while let Some(response) = recv_resp.recv().await {
|
||||
println!("{}", response);
|
||||
println!("{response}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use std::fs;
|
|||
async fn main() -> Result<()> {
|
||||
let input = fs::read_to_string("fixtures/elvis.html").unwrap();
|
||||
let links = Extractor::extract(&InputContent::from_string(&input, FileType::Html));
|
||||
println!("{:#?}", links);
|
||||
println!("{links:#?}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,6 +151,6 @@ fn show_progress(progress_bar: &Option<ProgressBar>, response: &Response, verbos
|
|||
if (response.status().is_success() || response.status().is_excluded()) && !verbose {
|
||||
return;
|
||||
}
|
||||
println!("{}", out);
|
||||
println!("{out}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ where
|
|||
// to another program like `grep`.
|
||||
if let Err(e) = write(&request, verbose) {
|
||||
if e.kind() != io::ErrorKind::BrokenPipe {
|
||||
eprintln!("{}", e);
|
||||
eprintln!("{e}");
|
||||
return Ok(ExitCode::UnexpectedFailure);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ fn load_cache(cfg: &Config) -> Option<Cache> {
|
|||
match cache {
|
||||
Ok(cache) => Some(cache),
|
||||
Err(e) => {
|
||||
println!("Error while loading cache: {}. Continuing without.", e);
|
||||
println!("Error while loading cache: {e}. Continuing without.");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
@ -247,7 +247,7 @@ fn write_stats(stats: ResponseStats, cfg: &Config) -> Result<()> {
|
|||
println!();
|
||||
}
|
||||
// we assume that the formatted stats don't have a final newline
|
||||
println!("{}", formatted);
|
||||
println!("{formatted}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub(crate) fn print_errors(stats: &ResponseStats) -> String {
|
|||
let mut err: Vec<_> = errors
|
||||
.into_iter()
|
||||
.filter(|(_, v)| *v > 0)
|
||||
.map(|(k, v)| format!("{}:{}", k, v))
|
||||
.map(|(k, v)| format!("{k}:{v}"))
|
||||
.collect();
|
||||
err.sort();
|
||||
err.join("|")
|
||||
|
|
@ -37,10 +37,16 @@ impl Display for CompactResponseStats {
|
|||
let stats = &self.0;
|
||||
|
||||
if !stats.fail_map.is_empty() {
|
||||
let input = if stats.fail_map.len() == 1 {
|
||||
"input"
|
||||
} else {
|
||||
"inputs"
|
||||
};
|
||||
|
||||
color!(
|
||||
f,
|
||||
BOLD_PINK,
|
||||
"Issues found in {} input(s). Find details below.\n\n",
|
||||
"Issues found in {} {input}. Find details below.\n\n",
|
||||
stats.fail_map.len()
|
||||
)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -327,8 +327,7 @@ mod cli {
|
|||
.failure()
|
||||
.code(1)
|
||||
.stderr(contains(format!(
|
||||
"Error: Failed to read from path: `{}`, reason: No such file or directory (os error 2)",
|
||||
filename
|
||||
"Error: Failed to read from path: `{filename}`, reason: No such file or directory (os error 2)"
|
||||
)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ mod test {
|
|||
|
||||
let expected_urls = HashSet::from_iter([
|
||||
website("https://github.com/lycheeverse/lychee/"),
|
||||
website(&format!("{}about", server_uri)),
|
||||
website(&format!("{server_uri}about")),
|
||||
]);
|
||||
|
||||
assert_eq!(links, expected_urls);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
//! #[tokio::main]
|
||||
//! async fn main() -> Result<()> {
|
||||
//! let response = lychee_lib::check("https://github.com/lycheeverse/lychee").await?;
|
||||
//! println!("{}", response);
|
||||
//! println!("{response}");
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
|
|
|
|||
|
|
@ -63,8 +63,7 @@ impl Default for Quirks {
|
|||
let mut out = request;
|
||||
if let Some(id) = query(&out).get("v") {
|
||||
*out.url_mut() =
|
||||
Url::parse(&format!("https://img.youtube.com/vi/{}/0.jpg", &id))
|
||||
.unwrap();
|
||||
Url::parse(&format!("https://img.youtube.com/vi/{id}/0.jpg")).unwrap();
|
||||
}
|
||||
out
|
||||
},
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ impl Input {
|
|||
let content: InputContent = Self::path_content(&path).await?;
|
||||
yield content;
|
||||
}
|
||||
Err(e) => println!("{:?}", e),
|
||||
Err(e) => println!("{e:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ pub(crate) fn error_from_output(o: &CheckEmailOutput) -> String {
|
|||
if let Err(_e) = o.misc.as_ref() {
|
||||
return "Error occurred connecting to this email server via SMTP".to_string();
|
||||
} else if let Err(e) = &o.smtp {
|
||||
return format!("{:?}", e);
|
||||
return format!("{e:?}");
|
||||
} else if let Err(e) = &o.mx {
|
||||
return format!("{:?}", e);
|
||||
return format!("{e:?}");
|
||||
}
|
||||
match &o.is_reachable {
|
||||
Reachable::Safe => "Safe: The email is safe to send",
|
||||
|
|
|
|||
Loading…
Reference in a new issue