Struct stdweb::UnsafeTypedArray [] [src]

pub struct UnsafeTypedArray<'a, T: 'a>(_);

A wrapper type for exposing raw Rust slices as TypedArrays at zero cost without copying.

The only thing you can do with this is to pass it to the js! macro.

Using this is highly unsafe! After you pass it to the js! macro you must use it before triggering any Rust code whatsoever, either directly or indirectly. Breaking this rule will result in undefined behavior!

Examples

let slice: &[u8] = &[1, 2, 3];
let slice = unsafe { UnsafeTypedArray::new( slice ) };
js!(
    var slice = @{slice};
    // `slice` is an Uint8Array
    var sum = slice[0] + slice[1] + slice[2];
    console.log( "Sum of array elements: ", sum );
);

Methods

impl<'a, T> UnsafeTypedArray<'a, T>
[src]

[src]

Creates a new UnsafeTypedArray.

Even though this function is marked as unsafe the unsafely only comes into play after you pass it to the js! macro.

Trait Implementations

impl<'a, T> Debug for UnsafeTypedArray<'a, T>
[src]

[src]

Formats the value using the given formatter.