From a4327a04b718e5b71f399a1cea456523fb1064d1 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Sun, 11 Aug 2024 14:54:04 -0700 Subject: [PATCH] style: simplify string formatting --- crates/neon/src/types_impl/buffer/types.rs | 3 +-- crates/neon/src/types_impl/error.rs | 4 ++-- crates/neon/src/types_impl/utf8.rs | 2 +- test/napi/src/js/errors.rs | 2 +- test/napi/src/js/threads.rs | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/neon/src/types_impl/buffer/types.rs b/crates/neon/src/types_impl/buffer/types.rs index fb4583534..8ac3b30f4 100644 --- a/crates/neon/src/types_impl/buffer/types.rs +++ b/crates/neon/src/types_impl/buffer/types.rs @@ -657,8 +657,7 @@ where if (len * elt_size) != size { return cx.throw_range_error(format!( - "byte length of typed array should be a multiple of {}", - elt_size + "byte length of typed array should be a multiple of {elt_size}" )); } diff --git a/crates/neon/src/types_impl/error.rs b/crates/neon/src/types_impl/error.rs index bfc98b317..98fc404b8 100644 --- a/crates/neon/src/types_impl/error.rs +++ b/crates/neon/src/types_impl/error.rs @@ -121,9 +121,9 @@ pub(crate) fn convert_panics NeonResult>( Ok(result) => result, Err(panic) => { let msg = if let Some(string) = panic.downcast_ref::() { - format!("internal error in Neon module: {}", string) + format!("internal error in Neon module: {string}") } else if let Some(str) = panic.downcast_ref::<&str>() { - format!("internal error in Neon module: {}", str) + format!("internal error in Neon module: {str}") } else { "internal error in Neon module".to_string() }; diff --git a/crates/neon/src/types_impl/utf8.rs b/crates/neon/src/types_impl/utf8.rs index 5f2ce6565..fe772edf4 100644 --- a/crates/neon/src/types_impl/utf8.rs +++ b/crates/neon/src/types_impl/utf8.rs @@ -47,7 +47,7 @@ impl<'a> Utf8<'a> { pub fn into_small_unwrap(self) -> SmallUtf8<'a> { let size = self.size(); self.into_small().unwrap_or_else(|| { - panic!("{} >= i32::MAX", size); + panic!("{size} >= i32::MAX"); }) } diff --git a/test/napi/src/js/errors.rs b/test/napi/src/js/errors.rs index c22e4da87..1e8f5233f 100644 --- a/test/napi/src/js/errors.rs +++ b/test/napi/src/js/errors.rs @@ -27,7 +27,7 @@ pub fn throw_error(mut cx: FunctionContext) -> JsResult { pub fn downcast_error(mut cx: FunctionContext) -> JsResult { let s = cx.string("hi"); if let Err(e) = s.downcast::(&mut cx) { - Ok(cx.string(format!("{}", e))) + Ok(cx.string(format!("{e}"))) } else { panic!() } diff --git a/test/napi/src/js/threads.rs b/test/napi/src/js/threads.rs index b8f5c892e..a55a656fc 100644 --- a/test/napi/src/js/threads.rs +++ b/test/napi/src/js/threads.rs @@ -195,7 +195,7 @@ pub fn channel_join(mut cx: FunctionContext) -> JsResult { .unwrap(); // Process the message - let response = format!("Received: {}", message); + let response = format!("Received: {message}"); // Call back to JavaScript with the response channel.send(move |mut cx| {