Skip to content

Commit 86937b9

Browse files
committed
Adding in From impl for TypedArrays
1 parent e106ca3 commit 86937b9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/js-sys/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4589,6 +4589,17 @@ macro_rules! arrays {
45894589
all_wasm_memory.set(self, offset as u32);
45904590
}
45914591
}
4592+
4593+
impl<'a> From<&'a [$ty]> for $name {
4594+
#[inline]
4595+
fn from(slice: &'a [$ty]) -> $name {
4596+
// TODO if this was written in JS it could avoid passing the `view` TypedArray to Rust,
4597+
// which would be more efficient
4598+
4599+
// This is safe because the `new` function makes a copy if its argument is a TypedArray
4600+
unsafe { $name::new(&$name::view(slice)) }
4601+
}
4602+
}
45924603
)*);
45934604
}
45944605

0 commit comments

Comments
 (0)