From cbd4e4d1fcc4b020ee4a9fb523fbd394b80c2e03 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Mon, 28 Dec 2020 21:39:58 +0800 Subject: [PATCH] chore(napi): remove TryFrom for usize --- napi/src/js_values/number.rs | 10 ---------- test_module/src/array.rs | 5 ++--- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/napi/src/js_values/number.rs b/napi/src/js_values/number.rs index f3578de1..a81f45d5 100644 --- a/napi/src/js_values/number.rs +++ b/napi/src/js_values/number.rs @@ -6,16 +6,6 @@ use crate::{sys, Error, Result}; pub struct JsNumber(pub(crate) Value); -impl TryFrom for usize { - type Error = Error; - - fn try_from(value: JsNumber) -> Result { - let mut result = 0; - check_status!(unsafe { sys::napi_get_value_int64(value.0.env, value.0.value, &mut result) })?; - Ok(result as usize) - } -} - impl TryFrom for u32 { type Error = Error; diff --git a/test_module/src/array.rs b/test_module/src/array.rs index 2348320b..3df64fd6 100644 --- a/test_module/src/array.rs +++ b/test_module/src/array.rs @@ -12,9 +12,8 @@ fn test_create_array(env: Env) -> ContextlessResult { #[js_function(1)] fn test_create_array_with_length(ctx: CallContext) -> Result { - ctx - .env - .create_array_with_length(ctx.get::(0)?.try_into()?) + let length: u32 = ctx.get::(0)?.try_into()?; + ctx.env.create_array_with_length(length as usize) } #[js_function(3)]