Skip to main content

Array

Struct Array 

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

Source

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.

Source§

impl<A: IVm> Array<A>

Source

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: Clone + IVm> Clone for Array<A>
where A::InternalArray: Clone,

Source§

fn clone(&self) -> Array<A>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: IVm> Debug for Array<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: IVm> Default for Array<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A: IVm> From<Array<A>> for Unpacked<A>

Source§

fn from(value: Array<A>) -> Self

Converts to this type from the input type.
Source§

impl<A: IVm> Index<u32> for Array<A>

Source§

fn index(&self, index: u32) -> &Self::Output

Currently panics if out of bounds. TODO: Future versions may change to return Nullish::Undefined.

Source§

type Output = Any<A>

The returned type after indexing.
Source§

impl<A: IVm> IntoIterator for Array<A>

Source§

type Item = Any<A>

The type of the elements being iterated over.
Source§

type IntoIter = IndexIter<u32, Array<A>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<A: IVm> PartialEq for Array<A>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<A: IVm> TryFrom<Any<A>> for Array<A>

Source§

type Error = Any<A>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Any<A>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<A: IVm, const N: usize> TryFrom<Array<A>> for [Any<A>; N]

An array of exactly N items as a fixed-size Rust array, to destructure: let [tag, value]: [Any<A>; 2] = array.try_into()?. An array of any other length is handed back unchanged, as Vec’s conversion hands back the Vec.

Source§

type Error = Array<A>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Array<A>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<A> Freeze for Array<A>
where <A as IVm>::InternalArray: Freeze,

§

impl<A> RefUnwindSafe for Array<A>

§

impl<A> Send for Array<A>
where <A as IVm>::InternalArray: Send,

§

impl<A> Sync for Array<A>
where <A as IVm>::InternalArray: Sync,

§

impl<A> Unpin for Array<A>
where <A as IVm>::InternalArray: Unpin,

§

impl<A> UnsafeUnpin for Array<A>
where <A as IVm>::InternalArray: UnsafeUnpin,

§

impl<A> UnwindSafe for Array<A>
where <A as IVm>::InternalArray: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<W> SizedIndex<u32> for W
where W: ContainerWrapper,

Source§

fn length(&self) -> u32

Source§

fn is_empty(&self) -> bool

Source§

fn last(&self) -> Option<&Self::Output>

Source§

fn index_iter(self) -> IndexIter<I, Self> ⓘ
where Self: Sized,

Source§

impl<T> ToAny for T

Source§

fn to_any<A: IVm>(self) -> Any<A>
where Self: Into<Unpacked<A>>,

Source§

impl<T> ToArray for T

Source§

fn to_array<A: IVm>(self) -> Array<A>
where Self: Sized + IntoIterator<Item = Any<A>>,

Source§

impl<T> ToObject for T

Source§

fn to_object<A: IVm>(self) -> Object<A>
where Self: Sized + IntoIterator<Item = Property<A>>,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T

Source§

fn try_to_string<A: IVm>(self) -> Result<String<A>, Any<A>>
where Self: Sized + IntoIterator<Item = Result<u16, Any<A>>>,

Source§

fn to_string<A: IVm>(self) -> String<A>
where Self: Sized + IntoIterator<Item = u16>,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.