summaryrefslogtreecommitdiff
path: root/cli/util
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-01-27 10:43:16 -0500
committerGitHub <noreply@github.com>2023-01-27 10:43:16 -0500
commitf5840bdcd360ec0bac2501f333e58e25742b1537 (patch)
tree7eb0818d2cafa0f6824e81b6ed2cfb609830971e /cli/util
parent1a1faff2f67613ed0b89e1a34e6c3fd02ca6fd83 (diff)
chore: upgrade to Rust 1.67 (#17548)
Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/util')
-rw-r--r--cli/util/checksum.rs2
-rw-r--r--cli/util/display.rs8
-rw-r--r--cli/util/file_watcher.rs4
-rw-r--r--cli/util/fs.rs22
-rw-r--r--cli/util/path.rs15
-rw-r--r--cli/util/progress_bar/renderer.rs2
-rw-r--r--cli/util/text_encoding.rs2
-rw-r--r--cli/util/v8.rs2
8 files changed, 27 insertions, 30 deletions
diff --git a/cli/util/checksum.rs b/cli/util/checksum.rs
index 73eec19d2..38a372590 100644
--- a/cli/util/checksum.rs
+++ b/cli/util/checksum.rs
@@ -12,7 +12,7 @@ pub fn gen(v: &[impl AsRef<[u8]>]) -> String {
let out: Vec<String> = digest
.as_ref()
.iter()
- .map(|byte| format!("{:02x}", byte))
+ .map(|byte| format!("{byte:02x}"))
.collect();
out.join("")
}
diff --git a/cli/util/display.rs b/cli/util/display.rs
index ee3d2f2d6..96b6cf84e 100644
--- a/cli/util/display.rs
+++ b/cli/util/display.rs
@@ -23,7 +23,7 @@ pub fn human_size(size: f64) -> String {
.unwrap()
* 1_f64;
let unit = units[exponent as usize];
- format!("{}{}{}", negative, pretty_bytes, unit)
+ format!("{negative}{pretty_bytes}{unit}")
}
const BYTES_TO_KIB: u64 = 2u64.pow(10);
@@ -41,7 +41,7 @@ pub fn human_download_size(byte_count: u64, total_bytes: u64) -> String {
fn get_in_format(byte_count: u64, conversion: u64, suffix: &str) -> String {
let converted_value = byte_count / conversion;
let decimal = (byte_count % conversion) * 100 / conversion;
- format!("{}.{:0>2}{}", converted_value, decimal, suffix)
+ format!("{converted_value}.{decimal:0>2}{suffix}")
}
}
@@ -49,7 +49,7 @@ pub fn human_download_size(byte_count: u64, total_bytes: u64) -> String {
/// represents a human readable version of that time.
pub fn human_elapsed(elapsed: u128) -> String {
if elapsed < 1_000 {
- return format!("{}ms", elapsed);
+ return format!("{elapsed}ms");
}
if elapsed < 1_000 * 60 {
return format!("{}s", elapsed / 1000);
@@ -58,7 +58,7 @@ pub fn human_elapsed(elapsed: u128) -> String {
let seconds = elapsed / 1_000;
let minutes = seconds / 60;
let seconds_remainder = seconds % 60;
- format!("{}m{}s", minutes, seconds_remainder)
+ format!("{minutes}m{seconds_remainder}s")
}
pub fn write_to_stdout_ignore_sigpipe(
diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs
index 29213f0c9..05415f2a6 100644
--- a/cli/util/file_watcher.rs
+++ b/cli/util/file_watcher.rs
@@ -74,7 +74,7 @@ where
if let Err(err) = result {
let error_string = match err.downcast_ref::<JsError>() {
Some(e) => format_js_error(e),
- None => format!("{:?}", err),
+ None => format!("{err:?}"),
};
eprintln!(
"{}: {}",
@@ -130,7 +130,7 @@ pub struct PrintConfig {
fn create_print_after_restart_fn(clear_screen: bool) -> impl Fn() {
move || {
if clear_screen && atty::is(atty::Stream::Stderr) {
- eprint!("{}", CLEAR_SCREEN);
+ eprint!("{CLEAR_SCREEN}");
}
info!(
"{} File change detected! Restarting!",
diff --git a/cli/util/fs.rs b/cli/util/fs.rs
index cb9232f39..777b22c5f 100644
--- a/cli/util/fs.rs
+++ b/cli/util/fs.rs
@@ -29,7 +29,7 @@ pub fn atomic_write_file<T: AsRef<[u8]>>(
let rand: String = (0..4)
.map(|_| format!("{:02x}", rand::random::<u8>()))
.collect();
- let extension = format!("{}.tmp", rand);
+ let extension = format!("{rand}.tmp");
let tmp_file = filename.with_extension(extension);
write_file(&tmp_file, data, mode)?;
std::fs::rename(tmp_file, filename)?;
@@ -710,13 +710,13 @@ mod tests {
.to_string();
let expected: Vec<ModuleSpecifier> = [
"http://localhost:8080",
- &format!("{}/a.ts", root_dir_url),
- &format!("{}/b.js", root_dir_url),
- &format!("{}/c.tsx", root_dir_url),
- &format!("{}/child/README.md", root_dir_url),
- &format!("{}/child/e.mjs", root_dir_url),
- &format!("{}/child/f.mjsx", root_dir_url),
- &format!("{}/d.jsx", root_dir_url),
+ &format!("{root_dir_url}/a.ts"),
+ &format!("{root_dir_url}/b.js"),
+ &format!("{root_dir_url}/c.tsx"),
+ &format!("{root_dir_url}/child/README.md"),
+ &format!("{root_dir_url}/child/e.mjs"),
+ &format!("{root_dir_url}/child/f.mjsx"),
+ &format!("{root_dir_url}/d.jsx"),
"https://localhost:8080",
]
.iter()
@@ -748,9 +748,9 @@ mod tests {
.unwrap();
let expected: Vec<ModuleSpecifier> = [
- &format!("{}/child/README.md", root_dir_url),
- &format!("{}/child/e.mjs", root_dir_url),
- &format!("{}/child/f.mjsx", root_dir_url),
+ &format!("{root_dir_url}/child/README.md"),
+ &format!("{root_dir_url}/child/e.mjs"),
+ &format!("{root_dir_url}/child/f.mjsx"),
]
.iter()
.map(|f| ModuleSpecifier::parse(f).unwrap())
diff --git a/cli/util/path.rs b/cli/util/path.rs
index 76e2a1b6f..d073d80bd 100644
--- a/cli/util/path.rs
+++ b/cli/util/path.rs
@@ -64,8 +64,7 @@ pub fn specifier_to_file_path(
match result {
Ok(path) => Ok(path),
Err(()) => Err(uri_error(format!(
- "Invalid file path.\n Specifier: {}",
- specifier
+ "Invalid file path.\n Specifier: {specifier}"
))),
}
}
@@ -76,7 +75,7 @@ pub fn ensure_directory_specifier(
) -> ModuleSpecifier {
let path = specifier.path();
if !path.ends_with('/') {
- let new_path = format!("{}/", path);
+ let new_path = format!("{path}/");
specifier.set_path(&new_path);
}
specifier
@@ -135,7 +134,7 @@ pub fn relative_specifier(
Some(if text.starts_with("../") || text.starts_with("./") {
text
} else {
- format!("./{}", text)
+ format!("./{text}")
})
}
@@ -170,12 +169,12 @@ pub fn path_with_stem_suffix(path: &Path, suffix: &str) -> PathBuf {
ext
))
} else {
- path.with_file_name(format!("{}{}.{}", file_stem, suffix, ext))
+ path.with_file_name(format!("{file_stem}{suffix}.{ext}"))
};
}
}
- path.with_file_name(format!("{}{}", file_name, suffix))
+ path.with_file_name(format!("{file_name}{suffix}"))
} else {
path.with_file_name(suffix)
}
@@ -380,9 +379,7 @@ mod test {
assert_eq!(
actual.as_deref(),
expected,
- "from: \"{}\" to: \"{}\"",
- from_str,
- to_str
+ "from: \"{from_str}\" to: \"{to_str}\""
);
}
}
diff --git a/cli/util/progress_bar/renderer.rs b/cli/util/progress_bar/renderer.rs
index 41a27f3aa..0ea275e77 100644
--- a/cli/util/progress_bar/renderer.rs
+++ b/cli/util/progress_bar/renderer.rs
@@ -154,7 +154,7 @@ fn get_elapsed_text(elapsed: Duration) -> String {
let elapsed_secs = elapsed.as_secs();
let seconds = elapsed_secs % 60;
let minutes = elapsed_secs / 60;
- format!("[{:0>2}:{:0>2}]", minutes, seconds)
+ format!("[{minutes:0>2}:{seconds:0>2}]")
}
#[cfg(test)]
diff --git a/cli/util/text_encoding.rs b/cli/util/text_encoding.rs
index bb7d442e9..87067e909 100644
--- a/cli/util/text_encoding.rs
+++ b/cli/util/text_encoding.rs
@@ -39,7 +39,7 @@ pub fn convert_to_utf8<'a>(
.ok_or_else(|| ErrorKind::InvalidData.into()),
None => Err(Error::new(
ErrorKind::InvalidInput,
- format!("Unsupported charset: {}", charset),
+ format!("Unsupported charset: {charset}"),
)),
}
}
diff --git a/cli/util/v8.rs b/cli/util/v8.rs
index b6d6aa44e..6afaf285e 100644
--- a/cli/util/v8.rs
+++ b/cli/util/v8.rs
@@ -36,7 +36,7 @@ pub fn init_v8_flags(v8_flags: &[String], env_v8_flags: Vec<String>) {
.collect::<Vec<_>>();
if !unrecognized_v8_flags.is_empty() {
for f in unrecognized_v8_flags {
- eprintln!("error: V8 did not recognize flag '{}'", f);
+ eprintln!("error: V8 did not recognize flag '{f}'");
}
eprintln!("\nFor a list of V8 flags, use '--v8-flags=--help'");
std::process::exit(1);