pub struct Region<'cx, T: Binary> { /* private fields */ }
Expand description
Represents a typed region of an ArrayBuffer
.
A Region
can be created via the
Handle<JsArrayBuffer>::region()
or
JsTypedArray::region()
methods.
A region is not checked for validity until it is converted to
a typed array via to_typed_array()
or
JsTypedArray::from_region()
.
§Example
// Allocate a 16-byte ArrayBuffer and a uint32 array of length 2 (i.e., 8 bytes)
// starting at byte offset 4 of the buffer:
//
// 0 4 8 12 16
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// buf: | | | | | | | | | | | | | | | | |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// ^ ^
// | |
// +-------+-------+
// arr: | | |
// +-------+-------+
// 0 1 2
let buf = cx.array_buffer(16)?;
let arr = JsUint32Array::from_region(&mut cx, &buf.region(4, 2))?;
Implementations§
source§impl<'cx, T> Region<'cx, T>
impl<'cx, T> Region<'cx, T>
sourcepub fn buffer(&self) -> Handle<'cx, JsArrayBuffer>
pub fn buffer(&self) -> Handle<'cx, JsArrayBuffer>
Returns the handle to the region’s buffer.
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the size of the region in bytes, which is equal to
(self.len() * size_of::<T>())
.
sourcepub fn to_typed_array<'c, C>(&self, cx: &mut C) -> JsResult<'c, JsTypedArray<T>>where
C: Context<'c>,
pub fn to_typed_array<'c, C>(&self, cx: &mut C) -> JsResult<'c, JsTypedArray<T>>where
C: Context<'c>,
Constructs a typed array for this buffer region.
The resulting typed array has self.len()
elements and a size of
self.size()
bytes.
Throws an exception if the region is invalid, for example if the starting offset is not properly aligned, or the length goes beyond the end of the buffer.
Trait Implementations§
impl<'cx, T: Copy + Binary> Copy for Region<'cx, T>
Auto Trait Implementations§
impl<'cx, T> Freeze for Region<'cx, T>
impl<'cx, T> RefUnwindSafe for Region<'cx, T>where
T: RefUnwindSafe,
impl<'cx, T> !Send for Region<'cx, T>
impl<'cx, T> !Sync for Region<'cx, T>
impl<'cx, T> Unpin for Region<'cx, T>where
T: Unpin,
impl<'cx, T> UnwindSafe for Region<'cx, T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more