pub struct Array<A: IVm>(/* private fields */);Expand description
use nanvm_lib::{
vm::{ToArray, IVm, Array, Any, Number, ToAny},
common::{sized_index::SizedIndex, default::default},
naive::Naive
};
fn array_test<A: IVm>() {
let b: Array<A> = [Number::from(1.0).to_any(), true.to_any()].to_array();
assert_eq!(b.length(), 2);
assert_eq!(b[0], Number::from(1.0).to_any());
assert_eq!(b[1], true.to_any());
let b1: Array<A> = [Number::from(1.0).to_any(), true.to_any()].to_array();
assert_eq!(b, b);
assert_ne!(b, b1);
let ac: Any<A> = b.clone().to_any();
let d: Array<A> = ac.try_into().unwrap();
assert_eq!(d, b);
let e0: Array<A> = default();
let e1: Array<A> = [].to_array();
assert_ne!(e0, e1);
}
array_test::<Naive>();Implementations§
Source§impl<A: IVm> Array<A>
impl<A: IVm> Array<A>
Sourcepub fn argument(&self, i: u32) -> Any<A>
pub fn argument(&self, i: u32) -> Any<A>
The i-th argument of a call whose arguments this array holds, or
undefined past the end, as JavaScript binds a parameter the call
left out. What a built-in and a compiled function’s body read their
fixed arguments with: one bounds check and one clone, where
Index<u32> panics past the end.
Sourcepub fn present(&self, i: u32) -> Option<Any<A>>
pub fn present(&self, i: u32) -> Option<Any<A>>
The i-th argument if the call passed one, undefined included,
and None if it did not: for a reader whose answer depends on
whether an argument is there, not only on its value —
lastIndexOf(x) searches from the end, lastIndexOf(x, undefined)
from 0, and an effect’s optional parameter is absent.
Source§impl<A: IVm> Array<A>
impl<A: IVm> Array<A>
Sourcepub fn rest(&self, i: u32) -> Array<A>
pub fn rest(&self, i: u32) -> Array<A>
The arguments from the i-th on, as a rest parameter of a call
whose arguments this array holds reads them: the array itself for
i == 0, since nothing is skipped, and a new array of the items
from i otherwise — empty when i is past the end.
The array is the call’s own: a call step builds it from the
argument list, a spread iterated, so no program holds it but the
callee, and answering it as the rest shares nothing a program can
see (fjs/edag/README.md, “An engine may form the arguments the
way the callee reads them”). A host calling Any::call with an
array it keeps is handing the callee that array, and reads it back
as the rest.
Trait Implementations§
Source§impl<A: IVm> IntoIterator for Array<A>
impl<A: IVm> IntoIterator for Array<A>
Auto Trait Implementations§
impl<A> Freeze for Array<A>
impl<A> RefUnwindSafe for Array<A>
impl<A> Send for Array<A>
impl<A> Sync for Array<A>
impl<A> Unpin for Array<A>
impl<A> UnsafeUnpin for Array<A>
impl<A> UnwindSafe for Array<A>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<W> SizedIndex<u32> for Wwhere
W: ContainerWrapper,
impl<W> SizedIndex<u32> for Wwhere
W: ContainerWrapper,
fn length(&self) -> u32
fn is_empty(&self) -> bool
Source§fn get(&self, i: I) -> Option<&Self::Output>
fn get(&self, i: I) -> Option<&Self::Output>
i if it is below length, and None past
the end, where Index panics: the bound every reader of an element
that may be absent would otherwise write for itself.