pub struct JsArray(/* private fields */);
Expand description
The type of JavaScript
Array
objects.
An array is any JavaScript value for which
Array.isArray
would return true
.
§Example
// Create a new empty array:
let a: Handle<JsArray> = cx.empty_array();
// Push some values onto the array:
a.prop(&mut cx, 0).set(17)?;
a.prop(&mut cx, 1).set("hello")?;
Implementations§
Source§impl JsArray
impl JsArray
Sourcepub fn new<'a, C: Context<'a>>(cx: &mut C, len: usize) -> Handle<'a, JsArray>
pub fn new<'a, C: Context<'a>>(cx: &mut C, len: usize) -> Handle<'a, JsArray>
Constructs a new empty array of length len
, equivalent to the JavaScript
expression new Array(len)
.
Note that for non-zero len
, this creates a
sparse array,
which can sometimes have surprising behavior. To ensure that a new array
is and remains dense (i.e., not sparse), consider creating an empty array
with JsArray::new(cx, 0)
or cx.empty_array()
and only appending
elements to the end of the array.
See also: Context::empty_array
Sourcepub fn to_vec<'a, C: Context<'a>>(
&self,
cx: &mut C,
) -> NeonResult<Vec<Handle<'a, JsValue>>>
pub fn to_vec<'a, C: Context<'a>>( &self, cx: &mut C, ) -> NeonResult<Vec<Handle<'a, JsValue>>>
Copies the array contents into a new Vec
by iterating through all indices
from 0 to self.len()
.
The length is dynamically checked on each iteration in case the array is modified during the computation.
Trait Implementations§
Source§impl Object for JsArray
impl Object for JsArray
Source§fn prop<'a, 'cx: 'a, K: PropertyKey>(
&self,
cx: &'a mut Cx<'cx>,
key: K,
) -> PropOptions<'a, 'cx, Self, K>
fn prop<'a, 'cx: 'a, K: PropertyKey>( &self, cx: &'a mut Cx<'cx>, key: K, ) -> PropOptions<'a, 'cx, Self, K>
Create a
PropOptions
for accessing a property. Read moreSource§fn method<'a, 'cx: 'a, K: PropertyKey>(
&self,
cx: &'a mut Cx<'cx>,
key: K,
) -> NeonResult<BindOptions<'a, 'cx>>
fn method<'a, 'cx: 'a, K: PropertyKey>( &self, cx: &'a mut Cx<'cx>, key: K, ) -> NeonResult<BindOptions<'a, 'cx>>
Gets a property from the object as a method and binds
this
to the object. Read moreSource§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>>>
👎Deprecating in a future version: use
Object::prop()
insteadSource§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>>
👎Deprecating in a future version: use
Object::prop()
insteadSource§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>>
👎Deprecating in a future version: use
Object::prop()
insteadSource§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>
Available on crate feature
napi-6
only.fn freeze<'a, C: Context<'a>>(&self, cx: &mut C) -> NeonResult<&Self>
fn seal<'a, C: Context<'a>>(&self, cx: &mut C) -> NeonResult<&Self>
Source§fn set<'a, C: Context<'a>, K: PropertyKey, W: Value>(
&self,
cx: &mut C,
key: K,
val: Handle<'_, W>,
) -> NeonResult<bool>
fn set<'a, C: Context<'a>, K: PropertyKey, W: Value>( &self, cx: &mut C, key: K, val: Handle<'_, W>, ) -> NeonResult<bool>
👎Deprecating in a future version: use
Object::prop()
insteadfn root<'a, C: Context<'a>>(&self, cx: &mut C) -> Root<Self>
Source§fn call_method_with<'a, C, K>(
&self,
cx: &mut C,
method: K,
) -> NeonResult<CallOptions<'a>>where
C: Context<'a>,
K: PropertyKey,
fn call_method_with<'a, C, K>(
&self,
cx: &mut C,
method: K,
) -> NeonResult<CallOptions<'a>>where
C: Context<'a>,
K: PropertyKey,
👎Deprecating in a future version: use
Object::method()
insteadSource§impl Value for JsArray
impl Value for JsArray
Auto Trait Implementations§
impl Freeze for JsArray
impl RefUnwindSafe for JsArray
impl !Send for JsArray
impl !Sync for JsArray
impl Unpin for JsArray
impl UnwindSafe for JsArray
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> 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