Skip to content

A wrapper for all typed array types from `js_sys` that implements common functionality and useful conversions.

Notifications You must be signed in to change notification settings

ThomasdenH/typed-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typed-array

Build Status

A wrapper for all typed array types from js_sys that implements common functionality and useful conversions.

All typed arrays in Javascript have properties like buffer, subarray and byte_length in common. However, they can be tricky to work with if the variant is not known. This wrapper type makes it easy to use all typed arrays in the way you'd expect.

Examples

use typed_array::TypedArray;
use js_sys::Uint8Array;

fn length_of_typed_array<T: Into<TypedArray>>(typed_array: T) -> u32 {
    typed_array.into().length()
}

assert_eq!(
    length_of_typed_array(Uint8Array::new(&10.into())),
    10
);

Features

The following common functionality between typed arrays is implemented:

Additionally, conversions are easy:

  • From<X> for TypedArray
  • TryFrom<TypedArray> for X
  • TryFrom<JsValue> for TypedArray
  • AsRef<JsValue> for TypedArray
  • AsRef<Object> for TypedArray
  • has_type, analogous to JsCast::has_type
  • dyn_into, analogous to JsCast::dyn_into

About

A wrapper for all typed array types from `js_sys` that implements common functionality and useful conversions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages