feat(napi): impl chained Into for TypedArray types (#1978)

This commit is contained in:
LongYinan 2024-02-25 00:58:27 +08:00 committed by GitHub
parent 3e187151a6
commit f88a041fa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -573,3 +573,64 @@ impl<T: Into<Vec<u8>>> From<T> for Uint8Array {
Uint8Array::new(data.into())
}
}
impl<T: Into<Vec<u8>>> From<T> for Uint8ClampedArray {
fn from(data: T) -> Self {
Uint8ClampedArray::new(data.into())
}
}
impl<T: Into<Vec<u16>>> From<T> for Uint16Array {
fn from(data: T) -> Self {
Uint16Array::new(data.into())
}
}
impl<T: Into<Vec<u32>>> From<T> for Uint32Array {
fn from(data: T) -> Self {
Uint32Array::new(data.into())
}
}
impl<T: Into<Vec<i8>>> From<T> for Int8Array {
fn from(data: T) -> Self {
Int8Array::new(data.into())
}
}
impl<T: Into<Vec<i16>>> From<T> for Int16Array {
fn from(data: T) -> Self {
Int16Array::new(data.into())
}
}
impl<T: Into<Vec<i32>>> From<T> for Int32Array {
fn from(data: T) -> Self {
Int32Array::new(data.into())
}
}
impl<T: Into<Vec<f32>>> From<T> for Float32Array {
fn from(data: T) -> Self {
Float32Array::new(data.into())
}
}
impl<T: Into<Vec<f64>>> From<T> for Float64Array {
fn from(data: T) -> Self {
Float64Array::new(data.into())
}
}
#[cfg(feature = "napi6")]
impl<T: Into<Vec<i64>>> From<T> for BigInt64Array {
fn from(data: T) -> Self {
BigInt64Array::new(data.into())
}
}
#[cfg(feature = "napi6")]
impl<T: Into<Vec<u64>>> From<T> for BigUint64Array {
fn from(data: T) -> Self {
BigUint64Array::new(data.into())
}
}