pub trait TypedArray: Value {
type Item: Binary;
// Required methods
fn as_slice<'cx, 'a, C>(&self, cx: &'a C) -> &'a [Self::Item]
where C: Context<'cx>;
fn as_mut_slice<'cx, 'a, C>(
&mut self,
cx: &'a mut C,
) -> &'a mut [Self::Item]
where C: Context<'cx>;
fn try_borrow<'cx, 'a, C>(
&self,
lock: &'a Lock<'_, C>,
) -> Result<Ref<'a, Self::Item>, BorrowError>
where C: Context<'cx>;
fn try_borrow_mut<'cx, 'a, C>(
&mut self,
lock: &'a Lock<'_, C>,
) -> Result<RefMut<'a, Self::Item>, BorrowError>
where C: Context<'cx>;
fn size<'cx, C>(&self, cx: &mut C) -> usize
where C: Context<'cx>;
fn from_slice<'cx, C>(
cx: &mut C,
slice: &[Self::Item],
) -> JsResult<'cx, Self>
where C: Context<'cx>;
}
Expand description
A trait allowing Rust to borrow binary data from the memory buffer of JavaScript typed arrays.
This trait provides both statically and dynamically checked borrowing. As usual in Rust, mutable borrows are guaranteed not to overlap with other borrows.
§Example
use neon::types::buffer::TypedArray;
fn double(mut cx: FunctionContext) -> JsResult<JsUndefined> {
let mut array: Handle<JsUint32Array> = cx.argument(0)?;
for elem in array.as_mut_slice(&mut cx).iter_mut() {
*elem *= 2;
}
Ok(cx.undefined())
}
Required Associated Types§
Required Methods§
Sourcefn as_slice<'cx, 'a, C>(&self, cx: &'a C) -> &'a [Self::Item]where
C: Context<'cx>,
fn as_slice<'cx, 'a, C>(&self, cx: &'a C) -> &'a [Self::Item]where
C: Context<'cx>,
Statically checked immutable borrow of binary data.
This may not be used if a mutable borrow is in scope. For the dynamically
checked variant see TypedArray::try_borrow
.
Sourcefn as_mut_slice<'cx, 'a, C>(&mut self, cx: &'a mut C) -> &'a mut [Self::Item]where
C: Context<'cx>,
fn as_mut_slice<'cx, 'a, C>(&mut self, cx: &'a mut C) -> &'a mut [Self::Item]where
C: Context<'cx>,
Statically checked mutable borrow of binary data.
This may not be used if any other borrow is in scope. For the dynamically
checked variant see TypedArray::try_borrow_mut
.
Sourcefn try_borrow<'cx, 'a, C>(
&self,
lock: &'a Lock<'_, C>,
) -> Result<Ref<'a, Self::Item>, BorrowError>where
C: Context<'cx>,
fn try_borrow<'cx, 'a, C>(
&self,
lock: &'a Lock<'_, C>,
) -> Result<Ref<'a, Self::Item>, BorrowError>where
C: Context<'cx>,
Dynamically checked immutable borrow of binary data, returning an error if the the borrow would overlap with a mutable borrow.
The borrow lasts until Ref
exits scope.
This is the dynamically checked version of TypedArray::as_slice
.
Sourcefn try_borrow_mut<'cx, 'a, C>(
&mut self,
lock: &'a Lock<'_, C>,
) -> Result<RefMut<'a, Self::Item>, BorrowError>where
C: Context<'cx>,
fn try_borrow_mut<'cx, 'a, C>(
&mut self,
lock: &'a Lock<'_, C>,
) -> Result<RefMut<'a, Self::Item>, BorrowError>where
C: Context<'cx>,
Dynamically checked mutable borrow of binary data, returning an error if the the borrow would overlap with an active borrow.
The borrow lasts until RefMut
exits scope.
This is the dynamically checked version of TypedArray::as_mut_slice
.
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.