mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-19 16:01:23 +00:00
Implement support for Uint8ClampedArray
This commit implements support for binding APIs that take `Uint8ClampedArray` in JS. This is pretty rare but comes up in a `web-sys` binding or two, and we're now able to bind these APIs instead of having to omit the bindings. The `Uint8ClampedArray` type is bound by using the `Clamped` marker struct in Rust. For example this is declaring a JS API that takes `Uint8ClampedArray`: use wasm_bindgen::Clamped; #[wasm_bindgen] extern { fn takes_clamped(a: Clamped<&[u8]>); } The `Clamped` type currently only works when wrapping the `&[u8]`, `&mut [u8]`, and `Vec<u8>` types. Everything else will produce an error at `wasm-bindgen` time. Closes #421
This commit is contained in:
@ -63,10 +63,10 @@ pub fn mdn_doc(class: &str, method: Option<&str>) -> String {
|
||||
}
|
||||
|
||||
// Array type is borrowed for arguments (`&[T]`) and owned for return value (`Vec<T>`).
|
||||
pub(crate) fn array(base_ty: &str, pos: TypePosition, mutable: bool) -> syn::Type {
|
||||
pub(crate) fn array(base_ty: &str, pos: TypePosition) -> syn::Type {
|
||||
match pos {
|
||||
TypePosition::Argument => {
|
||||
shared_ref(slice_ty(ident_ty(raw_ident(base_ty))), mutable)
|
||||
shared_ref(slice_ty(ident_ty(raw_ident(base_ty))), /*mutable =*/ true)
|
||||
}
|
||||
TypePosition::Return => {
|
||||
vec_ty(ident_ty(raw_ident(base_ty)))
|
||||
|
Reference in New Issue
Block a user