chore(napi): remove TryFrom<JsNumber> for usize

This commit is contained in:
LongYinan 2020-12-28 21:39:58 +08:00
parent 96b1abc00f
commit cbd4e4d1fc
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 2 additions and 13 deletions

View file

@ -6,16 +6,6 @@ use crate::{sys, Error, Result};
pub struct JsNumber(pub(crate) Value);
impl TryFrom<JsNumber> for usize {
type Error = Error;
fn try_from(value: JsNumber) -> Result<usize> {
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<JsNumber> for u32 {
type Error = Error;

View file

@ -12,9 +12,8 @@ fn test_create_array(env: Env) -> ContextlessResult<JsObject> {
#[js_function(1)]
fn test_create_array_with_length(ctx: CallContext) -> Result<JsObject> {
ctx
.env
.create_array_with_length(ctx.get::<JsNumber>(0)?.try_into()?)
let length: u32 = ctx.get::<JsNumber>(0)?.try_into()?;
ctx.env.create_array_with_length(length as usize)
}
#[js_function(3)]