Struct neon::types::JsArrayBuffer

source ·
#[repr(transparent)]
pub struct JsArrayBuffer(_);
Expand description

The standard JS ArrayBuffer type.

Example

use neon::types::buffer::TypedArray;

fn make_sequence(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {
    let len = cx.argument::<JsNumber>(0)?.value(&mut cx);
    let mut buffer = cx.array_buffer(len as usize)?;

    for (i, elem) in buffer.as_mut_slice(&mut cx).iter_mut().enumerate() {
        *elem = i as u8;
    }

    Ok(buffer)
}

Implementations§

Constructs a new JsArrayBuffer object, safely zero-filled.

Constructs a JsArrayBuffer from a slice by copying its contents.

This method is defined on JsArrayBuffer as a convenience and delegates to TypedArray::from_slice.

Available on crate feature external-buffers only.

Construct a new JsArrayBuffer from bytes allocated by Rust.

Compatibility Note

Some Node environments are built using V8’s sandboxed pointers functionality, which disallows the use of external buffers. In those environments, calling the underlying runtime function used by this method results in an immediate termination of the Node VM.

As a result, this API is disabled by default. If you are confident that your code will only be used in environments that disable sandboxed pointers, you can make use of this method by enabling the external-buffers feature flag.

Returns a region of this buffer.

See also: Handle<JsArrayBuffer>::region() for a more ergonomic form of this method.

Trait Implementations§

Formats the value using the given formatter. Read more
Gets a property from a JavaScript object that may be undefined and attempts to downcast the value if it existed. Read more
Gets a property from a JavaScript object as a JsValue. Read more
Gets a property from a JavaScript object and attempts to downcast as a specific type. Equivalent to calling obj.get_value(&mut cx)?.downcast_or_throw(&mut cx). Read more
Available on crate feature napi-6 only.
Statically checked immutable borrow of binary data. Read more
Statically checked mutable borrow of binary data. Read more
Dynamically checked immutable borrow of binary data, returning an error if the the borrow would overlap with a mutable borrow. Read more
Dynamically checked mutable borrow of binary data, returning an error if the the borrow would overlap with an active borrow. Read more
Returns the size, in bytes, of the allocated binary data.
Constructs an instance from a slice by copying its contents.

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 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.