pub struct JsBuffer(/* private fields */);
Expand description
The type of Node
Buffer
objects.
§Example
use neon::types::buffer::TypedArray;
fn make_sequence(mut cx: FunctionContext) -> JsResult<JsBuffer> {
let len = cx.argument::<JsNumber>(0)?.value(&mut cx);
let mut buffer = cx.buffer(len as usize)?;
for (i, elem) in buffer.as_mut_slice(&mut cx).iter_mut().enumerate() {
*elem = i as u8;
}
Ok(buffer)
}
Implementations§
source§impl JsBuffer
impl JsBuffer
sourcepub fn new<'a, C: Context<'a>>(cx: &mut C, len: usize) -> JsResult<'a, Self>
pub fn new<'a, C: Context<'a>>(cx: &mut C, len: usize) -> JsResult<'a, Self>
Constructs a new Buffer
object, safely zero-filled.
See also: Context::buffer
sourcepub fn from_slice<'cx, C>(cx: &mut C, slice: &[u8]) -> JsResult<'cx, Self>where
C: Context<'cx>,
pub fn from_slice<'cx, C>(cx: &mut C, slice: &[u8]) -> JsResult<'cx, Self>where
C: Context<'cx>,
Constructs a JsBuffer
from a slice by copying its contents.
This method is defined on JsBuffer
as a convenience and delegates to
TypedArray::from_slice
.
sourcepub unsafe fn uninitialized<'a, C: Context<'a>>(
cx: &mut C,
len: usize
) -> JsResult<'a, Self>
pub unsafe fn uninitialized<'a, C: Context<'a>>( cx: &mut C, len: usize ) -> JsResult<'a, Self>
Constructs a new Buffer
object with uninitialized memory
sourcepub fn external<'a, C, T>(cx: &mut C, data: T) -> Handle<'a, Self>
Available on crate feature external-buffers
only.
pub fn external<'a, C, T>(cx: &mut C, data: T) -> Handle<'a, Self>
external-buffers
only.Construct a new Buffer
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.
Trait Implementations§
source§impl Object for JsBuffer
impl Object for JsBuffer
source§fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Option<Handle<'a, V>>>
fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Option<Handle<'a, V>>>
undefined
and
attempts to downcast the value if it existed.source§fn get_value<'a, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, JsValue>>
fn get_value<'a, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Handle<'a, JsValue>>
source§fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, V>>
fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Handle<'a, V>>
obj.get_value(&mut cx)?.downcast_or_throw(&mut cx)
. Read moresource§fn get_own_property_names<'a, C: Context<'a>>(
&self,
cx: &mut C
) -> JsResult<'a, JsArray>
fn get_own_property_names<'a, C: Context<'a>>( &self, cx: &mut C ) -> JsResult<'a, JsArray>
napi-6
only.