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

Returns the handle to the region’s buffer.

Returns the starting byte offset of the region.

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

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

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.