Skip to content

Commit

Permalink
style: clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jan 28, 2023
1 parent aed2540 commit 18491fb
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bench/src/get_set_property.rs
Expand Up @@ -33,7 +33,7 @@ impl FromStr for LineJoin {
"miter" => Ok(Self::Miter),
_ => Err(Error::new(
Status::InvalidArg,
format!("[{}] is not valid LineJoin value", value),
format!("[{value}] is not valid LineJoin value"),
)),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/napi/src/env.rs
Expand Up @@ -357,7 +357,7 @@ impl Env {
&mut raw_value,
);
data = result_data.cast();
finalize(hint, self.clone());
finalize(hint, *self);
check_status!(status)?;
} else {
check_status!(status)?;
Expand Down Expand Up @@ -520,7 +520,7 @@ impl Env {
let status =
sys::napi_create_arraybuffer(self.0, length, &mut underlying_data, &mut raw_value);
data = underlying_data.cast();
finalize(hint, self.clone());
finalize(hint, *self);
check_status!(status)?;
} else {
check_status!(status)?;
Expand Down
2 changes: 1 addition & 1 deletion examples/napi-compat-mode/src/buffer.rs
Expand Up @@ -16,7 +16,7 @@ pub fn get_buffer_length(ctx: CallContext) -> Result<JsNumber> {
pub fn buffer_to_string(ctx: CallContext) -> Result<JsString> {
let buffer = ctx.get::<JsBuffer>(0)?.into_value()?;
ctx.env.create_string(
str::from_utf8(&buffer).map_err(|e| Error::new(Status::StringExpected, format!("{}", e)))?,
str::from_utf8(&buffer).map_err(|e| Error::new(Status::StringExpected, format!("{e}")))?,
)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/napi/src/async.rs
Expand Up @@ -9,7 +9,7 @@ async fn read_file_async(path: String) -> Result<Buffer> {
Ok(content) => Ok(content.into()),
Err(e) => Err(Error::new(
Status::GenericFailure,
format!("failed to read file, {}", e),
format!("failed to read file, {e}"),
)),
})
.await
Expand Down
10 changes: 5 additions & 5 deletions examples/napi/src/class.rs
Expand Up @@ -302,15 +302,15 @@ impl Optional {
pub fn option_end(required: String, optional: Option<String>) -> String {
match optional {
None => required,
Some(optional) => format!("{} {}", required, optional),
Some(optional) => format!("{required} {optional}"),
}
}

#[napi]
pub fn option_start(optional: Option<String>, required: String) -> String {
match optional {
None => required,
Some(optional) => format!("{} {}", optional, required),
Some(optional) => format!("{optional} {required}"),
}
}

Expand All @@ -322,9 +322,9 @@ impl Optional {
) -> String {
match (optional1, optional2) {
(None, None) => required,
(None, Some(optional2)) => format!("{} {}", required, optional2),
(Some(optional1), None) => format!("{} {}", optional1, required),
(Some(optional1), Some(optional2)) => format!("{} {} {}", optional1, required, optional2),
(None, Some(optional2)) => format!("{required} {optional2}"),
(Some(optional1), None) => format!("{optional1} {required}"),
(Some(optional1), Some(optional2)) => format!("{optional1} {required} {optional2}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/napi/src/either.rs
Expand Up @@ -11,7 +11,7 @@ fn either_string_or_number(input: Either<String, u32>) -> u32 {
#[napi]
fn return_either(input: u32) -> Either<String, u32> {
if input > 10 {
Either::A(format!("{}", input))
Either::A(format!("{input}"))
} else {
Either::B(input)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/napi/src/fn_ts_override.rs
Expand Up @@ -22,7 +22,7 @@ fn override_individual_arg_on_function(
.unwrap()
.to_string();

format!("oia: {}-{}-{}", not_overridden, not_overridden2, s)
format!("oia: {not_overridden}-{not_overridden2}-{s}")
}

#[napi]
Expand All @@ -32,5 +32,5 @@ fn override_individual_arg_on_function_with_cb_arg<
#[napi(ts_arg_type = "(town: string, name?: string | undefined | null) => string")] callback: T,
not_overridden: u32,
) -> Result<Object> {
callback(format!("World({})", not_overridden), None)
callback(format!("World({not_overridden})"), None)
}
4 changes: 2 additions & 2 deletions examples/napi/src/string.rs
Expand Up @@ -13,12 +13,12 @@ fn concat_str(mut s: String) -> String {

#[napi]
fn concat_utf16(s: Utf16String) -> Utf16String {
Utf16String::from(format!("{} + Rust 🦀 string!", s))
Utf16String::from(format!("{s} + Rust 🦀 string!"))
}

#[napi]
fn concat_latin1(s: Latin1String) -> String {
format!("{} + Rust 🦀 string!", s)
format!("{s} + Rust 🦀 string!")
}

#[napi]
Expand Down
4 changes: 2 additions & 2 deletions examples/napi/src/threadsafe_function.rs
Expand Up @@ -65,7 +65,7 @@ fn threadsafe_function_closure_capture(func: JsFunction) -> napi::Result<()> {
let str = "test";
let tsfn: ThreadsafeFunction<()> = func
.create_threadsafe_function(0, move |_| {
println!("{}", str); // str is NULL at this point
println!("{str}"); // str is NULL at this point
Ok(Vec::<JsString>::new())
})
.unwrap();
Expand All @@ -83,7 +83,7 @@ pub fn tsfn_call_with_callback(func: JsFunction) -> napi::Result<()> {
Ok(()),
ThreadsafeFunctionCallMode::NonBlocking,
|value: String| {
println!("{}", value);
println!("{value}");
assert_eq!(value, "ReturnFromJavaScriptRawCallback".to_owned());
Ok(())
},
Expand Down

1 comment on commit 18491fb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 18491fb Previous: fde2d64 Ratio
noop#napi-rs 52456688 ops/sec (±0.75%) 64268786 ops/sec (±0.27%) 1.23
noop#JavaScript 663734834 ops/sec (±0.86%) 710252276 ops/sec (±0.1%) 1.07
Plus number#napi-rs 15953415 ops/sec (±0.69%) 19701768 ops/sec (±0.6%) 1.23
Plus number#JavaScript 661714127 ops/sec (±0.85%) 708450052 ops/sec (±0.14%) 1.07
Create buffer#napi-rs 328130 ops/sec (±11.74%) 365131 ops/sec (±10.52%) 1.11
Create buffer#JavaScript 1773054 ops/sec (±4.66%) 1769743 ops/sec (±6.98%) 1.00
createArray#createArrayJson 35704 ops/sec (±0.68%) 38725 ops/sec (±0.11%) 1.08
createArray#create array for loop 5845 ops/sec (±0.65%) 7410 ops/sec (±0.12%) 1.27
createArray#create array with serde trait 5803 ops/sec (±0.48%) 7427 ops/sec (±0.12%) 1.28
getArrayFromJs#get array from json string 14792 ops/sec (±0.79%) 16367 ops/sec (±0.27%) 1.11
getArrayFromJs#get array from serde 7991 ops/sec (±0.63%) 10023 ops/sec (±0.04%) 1.25
getArrayFromJs#get array with for loop 9651 ops/sec (±1.48%) 12256 ops/sec (±0.1%) 1.27
Get Set property#Get Set from native#u32 371372 ops/sec (±6.45%) 415294 ops/sec (±6.57%) 1.12
Get Set property#Get Set from JavaScript#u32 316615 ops/sec (±6.14%) 357080 ops/sec (±6.76%) 1.13
Get Set property#Get Set from native#string 346715 ops/sec (±5.84%) 368692 ops/sec (±6.5%) 1.06
Get Set property#Get Set from JavaScript#string 285646 ops/sec (±5.72%) 341740 ops/sec (±6.86%) 1.20
Async task#spawn task 30508 ops/sec (±2.14%) 37096 ops/sec (±1.46%) 1.22
Async task#ThreadSafeFunction 2948 ops/sec (±5.57%) 1140 ops/sec (±23.02%) 0.39
Async task#Tokio future to Promise 28379 ops/sec (±2.8%) 31816 ops/sec (±0.65%) 1.12
Query#query * 100 1625 ops/sec (±2.41%) 2058 ops/sec (±3.31%) 1.27
Query#query * 1 26556 ops/sec (±2%) 31192 ops/sec (±0.3%) 1.17

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.