Struct neon::types::buffer::Region

source ·
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>
where T: Binary, JsTypedArray<T>: Value,

source

pub fn buffer(&self) -> Handle<'cx, JsArrayBuffer>

Returns the handle to the region’s buffer.

source

pub fn offset(&self) -> usize

Returns the starting byte offset of the region.

source

pub fn len(&self) -> usize

Returns the number of elements of type T in the region.

source

pub fn size(&self) -> usize

Returns the size of the region in bytes, which is equal to (self.len() * size_of::<T>()).

source

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§

source§

impl<'cx, T: Clone + Binary> Clone for Region<'cx, T>

source§

fn clone(&self) -> Region<'cx, T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.