Skip to content

Commit

Permalink
style: simplify string formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hamirmahal committed Aug 11, 2024
1 parent 37e43cc commit a4327a0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions crates/neon/src/types_impl/buffer/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
));
}

Expand Down
4 changes: 2 additions & 2 deletions crates/neon/src/types_impl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ pub(crate) fn convert_panics<T, F: UnwindSafe + FnOnce() -> NeonResult<T>>(
Ok(result) => result,
Err(panic) => {
let msg = if let Some(string) = panic.downcast_ref::<String>() {
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()
};
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
})
}

Expand Down
2 changes: 1 addition & 1 deletion test/napi/src/js/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn throw_error(mut cx: FunctionContext) -> JsResult<JsUndefined> {
pub fn downcast_error(mut cx: FunctionContext) -> JsResult<JsString> {
let s = cx.string("hi");
if let Err(e) = s.downcast::<JsNumber, _>(&mut cx) {
Ok(cx.string(format!("{}", e)))
Ok(cx.string(format!("{e}")))
} else {
panic!()
}
Expand Down
2 changes: 1 addition & 1 deletion test/napi/src/js/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn channel_join(mut cx: FunctionContext) -> JsResult<JsUndefined> {
.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| {
Expand Down

0 comments on commit a4327a0

Please sign in to comment.