ArrayView

Trait ArrayView 

Source
pub trait ArrayView: Sized {
    type JS: Deref<Target = Object>;

    const GL_TYPE: u32;

    // Required method
    unsafe fn view(rust: &[Self]) -> Self::JS;
}
Expand description

Idiomatic transformation of Rust arrays to JS.

This trait gives an idiomatic way to transform Rust arrays into a JS typed array (such as Float32Array) specifically for the use case of filling WebGL2 buffers and textures.

For this, each Rust numeric type is associated with a JS typed array type and with a constant that gives the corresponding WebGL2 data type (such as WebGL2RenderingContext::FLOAT).

Required Associated Constants§

Source

const GL_TYPE: u32

The associated WebGL2 data type.

Required Associated Types§

Source

type JS: Deref<Target = Object>

The associated JS typed array.

Required Methods§

Source

unsafe fn view(rust: &[Self]) -> Self::JS

Creates a JS typed array which is a view into wasm’s linear memory at the slice specified.

This function uses the view method (such as Float32Array::view) of the JS typed array.

§Safety

The same safety considerations as with Float32Array::view apply.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ArrayView for f32

Source§

const GL_TYPE: u32 = 5_126u32

Source§

type JS = Float32Array

Source§

unsafe fn view(rust: &[f32]) -> Float32Array

Source§

impl ArrayView for u8

Source§

const GL_TYPE: u32 = 5_121u32

Source§

type JS = Uint8Array

Source§

unsafe fn view(rust: &[u8]) -> Uint8Array

Source§

impl ArrayView for u16

Source§

const GL_TYPE: u32 = 5_125u32

Source§

type JS = Uint16Array

Source§

unsafe fn view(rust: &[u16]) -> Uint16Array

Implementors§