Skip to content

Commit

Permalink
Implement Into<JsValue> for boxed slices of numbers as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Liamolucko committed Sep 21, 2023
1 parent 1e67de6 commit 515baae
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,18 +1953,18 @@ impl From<JsError> for JsValue {
macro_rules! typed_arrays {
($($ty:ident $ctor:ident $clamped_ctor:ident,)*) => {
$(
impl From<Vec<$ty>> for JsValue {
fn from(mut vec: Vec<$ty>) -> Self {
let result = unsafe { JsValue::_new($ctor(vec.as_mut_ptr(), vec.len())) };
mem::forget(vec);
impl From<Box<[$ty]>> for JsValue {
fn from(mut vector: Box<[$ty]>) -> Self {
let result = unsafe { JsValue::_new($ctor(vector.as_mut_ptr(), vector.len())) };
mem::forget(vector);
result
}
}

impl From<Clamped<Vec<$ty>>> for JsValue {
fn from(mut vec: Clamped<Vec<$ty>>) -> Self {
let result = unsafe { JsValue::_new($clamped_ctor(vec.as_mut_ptr(), vec.len())) };
mem::forget(vec);
impl From<Clamped<Box<[$ty]>>> for JsValue {
fn from(mut vector: Clamped<Box<[$ty]>>) -> Self {
let result = unsafe { JsValue::_new($clamped_ctor(vector.as_mut_ptr(), vector.len())) };
mem::forget(vector);
result
}
}
Expand Down Expand Up @@ -2011,3 +2011,12 @@ where
JsValue::from(vector.into_boxed_slice())
}
}

impl<T> From<Clamped<Vec<T>>> for JsValue
where
JsValue: From<Clamped<Box<[T]>>>,
{
fn from(vector: Clamped<Vec<T>>) -> Self {
JsValue::from(Clamped(vector.0.into_boxed_slice()))
}
}

0 comments on commit 515baae

Please sign in to comment.