From 86937b9dbafaa96c4ef7a40f5bcf47d50a1927de Mon Sep 17 00:00:00 2001 From: Pauan Date: Mon, 24 Jun 2019 18:00:25 +0200 Subject: [PATCH] Adding in From impl for TypedArrays --- crates/js-sys/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index d96e784c..d5b49fcf 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -4589,6 +4589,17 @@ macro_rules! arrays { all_wasm_memory.set(self, offset as u32); } } + + impl<'a> From<&'a [$ty]> for $name { + #[inline] + fn from(slice: &'a [$ty]) -> $name { + // TODO if this was written in JS it could avoid passing the `view` TypedArray to Rust, + // which would be more efficient + + // This is safe because the `new` function makes a copy if its argument is a TypedArray + unsafe { $name::new(&$name::view(slice)) } + } + } )*); }