[][src]Struct xterm_js_sys::ReadOnlyArray

#[repr(transparent)]pub struct ReadOnlyArray<T: JsCast> {
    inner: Array,
    _t: PhantomData<T>,
}

Mirrors TypeScript's ReadOnlyArray interface.

This is built on the Array type in js-sys and primarily just mirrors over the subset of regular array functions that ReadOnlyArray provides. This wrapper also offers typed versions of all the functions that it forwards (prefixed with typed_).

Because wasm-bindgen doesn't support generic structs, this type uses #[repr(transparent)] and leans on its inner Array for all the wasm-bindgen specific impls.

Note that this struct does not provide an AsRef impl for Array as that would defeat the "read only" part of this type's guarantees.

Fields

inner: Array

The Array we're backed by.

_t: PhantomData<T>

Marker for T.

Implementations

impl<T: JsCast> ReadOnlyArray<T>[src]

#[must_use]pub fn get(&self, index: u32) -> JsValue[src]

Retrieves the element at the index (returns undefined if the index is out of range).

#[must_use]pub fn concat(&self, array: &Array) -> Array[src]

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

MDN documentation

#[must_use]pub fn every(
    &self,
    predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool
) -> bool
[src]

The every() method tests whether all elements in the array pass the test implemented by the provided function.

MDN documentation

#[must_use]pub fn filter(
    &self,
    predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool
) -> Array
[src]

The filter() method creates a new array with all elements that pass the test implemented by the provided function.

MDN documentation

#[must_use]pub fn find(
    &self,
    predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool
) -> JsValue
[src]

The find() method returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.

MDN documentation

#[must_use]pub fn find_index(
    &self,
    predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool
) -> i32
[src]

The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise -1 is returned.

MDN documentation

#[must_use]pub fn flat(&self, depth: i32) -> Array[src]

The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

MDN documentation

#[must_use]pub fn flat_map(
    &self,
    callback: &mut dyn FnMut(JsValue, u32, Array) -> Vec<JsValue>
) -> Array
[src]

The flatMap() method first maps each element using a mapping function, then flattens the result into a new array.

MDN documentation

pub fn for_each(&self, callback: &mut dyn FnMut(JsValue, u32, Array))[src]

The forEach() method executes a provided function once for each array element.

MDN documentation

#[must_use]pub fn includes(&self, value: &JsValue, from_index: i32) -> bool[src]

The includes() method determines whether an array includes a certain element, returning true or false as appropriate.

MDN documentation

#[must_use]pub fn index_of(&self, value: &JsValue, from_index: i32) -> i32[src]

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

MDN documentation

#[must_use]pub fn join(&self, delimiter: &str) -> JsString[src]

The join() method joins all elements of an array (or an array-like object) into a string and returns this string.

MDN documentation

#[must_use]pub fn last_index_of(&self, value: &JsValue, from_index: i32) -> i32[src]

The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.

MDN documentation

#[must_use]pub fn length(&self) -> u32[src]

The length property of an object which is an instance of type Array sets or returns the number of elements in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.

MDN documentation

#[must_use]pub fn map(
    &self,
    predicate: &mut dyn FnMut(JsValue, u32, Array) -> JsValue
) -> Array
[src]

map() calls a provided callback function once for each element in an array, in order, and constructs a new array from the results. callback is invoked only for indexes of the array which have assigned values, including undefined. It is not called for missing elements of the array (that is, indexes that have never been set, which have been deleted or which have never been assigned a value).

MDN documentation

#[must_use]pub fn reduce(
    &self,
    predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
    initial_value: &JsValue
) -> JsValue
[src]

The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.

MDN documentation

#[must_use]pub fn reduce_right(
    &self,
    predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
    initial_value: &JsValue
) -> JsValue
[src]

The reduceRight() method applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.

MDN documentation

#[must_use]pub fn slice(&self, start: u32, end: u32) -> Array[src]

The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified.

Note that because a copy is returned, the fact that an Array is produced from a ReadOnlyArray is not a problem.

MDN documentation

#[must_use]pub fn some(&self, predicate: &mut dyn FnMut(JsValue) -> bool) -> bool[src]

The some() method tests whether at least one element in the array passes the test implemented by the provided function.

Note: This method returns false for any condition put on an empty array.

MDN documentation

#[must_use]pub fn to_locale_string(&self, locales: &JsValue, options: &JsValue) -> JsString[src]

The toLocaleString() method returns a string representing the elements of the array. The elements are converted to Strings using their toLocaleString methods and these Strings are separated by a locale-specific String (such as a comma “,”).

MDN documentation

#[must_use]pub fn to_string(&self) -> JsString[src]

The toString() method returns a string representing the specified array and its elements.

MDN documentation

#[must_use]pub fn iter(&self) -> ArrayIter<'_>[src]

Returns an iterator over the values of the JS array.

#[must_use]pub fn to_vec(&self) -> Vec<JsValue>[src]

Converts the JS array into a new Vec.

#[must_use]pub fn keys(&self) -> Iterator[src]

The keys() method returns a new Array Iterator object that contains the keys for each index in the array.

MDN documentation

#[must_use]pub fn entries(&self) -> Iterator[src]

The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.

MDN documentation

#[must_use]pub fn values(&self) -> Iterator[src]

The values() method returns a new Array Iterator object that contains the values for each index in the array.

MDN documentation

#[must_use]pub fn is_array(value: &JsValue) -> bool[src]

The Array.isArray() method determines whether the passed value is an Array.

MDN documentation

impl<T: JsCast> ReadOnlyArray<T>[src]

#[must_use]pub fn typed_get(&self, index: u32) -> Option<T>[src]

Typed version of Array::get.

Returns None when the element can't be casted into T or the index is out of bounds.

#[must_use]pub fn typed_concat(&self, array: &Self) -> Self[src]

Typed version of Array::concat.

pub fn typed_every(&self, predicate: impl FnMut(T, u32, Self) -> bool) -> bool[src]

Typed version of Array::every.

Returns false is any of the elements can't be casted into T.

#[must_use]pub fn typed_filter(&self, predicate: impl FnMut(T, u32, Self) -> bool) -> Self[src]

Typed version of Array::filter.

Elements that can't be casted into T are automatically filtered out.

#[must_use]pub fn typed_find(
    &self,
    predicate: impl FnMut(T, u32, Self) -> bool
) -> Option<T>
[src]

Typed version of Array::find.

Elements that can't be casted into T are automatically ignored.

#[must_use]pub fn typed_find_index(
    &self,
    predicate: impl FnMut(T, u32, Self) -> bool
) -> Option<u32>
[src]

Typed version of Array::find_index.

Elements that can't be casted into T are automatically ignored.

Returns None when the element can't be found.

#[must_use]pub fn typed_flat(&self, depth: i32) -> Self[src]

Typed version of Array::flat.

#[must_use]pub fn typed_flat_map(
    &self,
    callback: impl FnMut(T, u32, Self) -> Vec<T>
) -> Self
[src]

Typed version of Array::flat_map.

Elements that can't be casted into T are automatically ignored.

pub fn typed_for_each(&self, callback: impl FnMut(T, u32, Self))[src]

Typed version of Array::for_each.

Elements that can't be casted into T are automatically ignored.

pub fn typed_includes(&self, value: T, from_index: i32) -> bool[src]

Typed version of Array::includes.

Note that this takes the element to search for by value (we have no way to convert from &T to &JsValue); if T impls AsRef<JsValue>, you're better off using ReadOnlyArray::includes; it will be cheaper (but possibly less ergonomic).

pub fn typed_index_of(&self, value: T, from_index: i32) -> Option<u32>[src]

Typed version of Array::index_of.

Note that this takes the element to search for by value (we have no way to convert from &T to &JsValue); if T impls AsRef<JsValue>, you're better off using ReadOnlyArray::index_of; it will be cheaper (but possibly less ergonomic).

Returns None when the element can't be found.

pub fn typed_last_index_of(&self, value: T, from_index: i32) -> Option<u32>[src]

Typed version of Array::last_index_of.

Note that this takes the element to search for by value (we have no way to convert from &T to &JsValue); if T impls AsRef<JsValue>, you're better off using ReadOnlyArray::last_index_of; it will be cheaper (but possibly less ergonomic).

Returns None when the element can't be found.

#[must_use]pub fn typed_map<R: JsCast>(
    &self,
    predicate: impl FnMut(T, u32, Self) -> R
) -> ReadOnlyArray<R>
[src]

Typed version of Array::map.

Elements that can't be cast into T are mapped to JsValue::UNDEFINED.

#[must_use]pub fn typed_reduce<A: JsCast>(
    &self,
    predicate: impl FnMut(A, T, u32, Self) -> A,
    initial_value: A
) -> A
[src]

Typed version of Array::reduce.

Effectively 'skips' elements that can't be cast to T (just returns the accumulator as is for those elements).

#[must_use]pub fn typed_reduce_right<A: JsCast>(
    &self,
    predicate: impl FnMut(A, T, u32, Self) -> A,
    initial_value: A
) -> A
[src]

Typed version of Array::reduce_right.

Effectively 'skips' elements that can't be cast to T (just returns the accumulator as is for those elements).

#[must_use]pub fn typed_slice(&self, start: u32, end: u32) -> Self[src]

Typed version of Array::slice.

#[must_use]pub fn typed_some(&self, predicate: impl FnMut(T) -> bool) -> bool[src]

Typed version of Array::some.

Elements that can't be casted into T are effectively ignored (false is returned).

pub fn typed_iter<'a>(&'a self) -> impl Iterator<Item = T> + 'a[src]

Typed version of Array::iter.

Elements that can't be casted into T are omitted.

#[must_use]pub fn typed_to_vec(&self) -> Vec<T>[src]

Typed version of Array::to_vec.

Elements that can't be casted into T are omitted.

pub fn typed_keys(&self) -> impl Iterator<Item = u32>[src]

Typed version of Array::keys.

pub fn typed_entries(&self) -> impl Iterator<Item = (u32, Result<T, JsValue>)>[src]

Typed version of Array::entries.

Returns Err(JsValue)s for elements that could not be casted as T and elements that would have caused TypeErrors (i.e. non-objects). See js_sys::Iterator::next for more details about the latter case.

pub fn typed_values(&self) -> impl Iterator<Item = Result<T, JsValue>>[src]

Typed version of Array::values.

Returns Err(JsValue)s for elements that could not be casted as T and elements that would have caused TypeErrors (i.e. non-objects). See js_sys::Iterator::next for more details about the latter case.

impl<T: JsCast> ReadOnlyArray<T>[src]

#[must_use]pub fn mutable_array_copy(&self) -> Array[src]

Produces a copy of the array that is mutable (i.e. an Array).

#[must_use]pub fn excluding_other_types(&self) -> Self[src]

Produces a copy of the array that excludes any elements that can't be cast as T.

Indexing into this array (for valid indexes), for example, should always produce Some(_)s.

Methods from Deref<Target = Object>

pub fn constructor(&self) -> Function[src]

This is supported on feature="ext" only.

The constructor property returns a reference to the Object constructor function that created the instance object.

MDN documentation

pub fn has_own_property(&self, property: &JsValue) -> bool[src]

This is supported on feature="ext" only.

The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it).

MDN documentation

pub fn is_prototype_of(&self, value: &JsValue) -> bool[src]

This is supported on feature="ext" only.

The isPrototypeOf() method checks if an object exists in another object's prototype chain.

MDN documentation

pub fn property_is_enumerable(&self, property: &JsValue) -> bool[src]

This is supported on feature="ext" only.

The propertyIsEnumerable() method returns a Boolean indicating whether the specified property is enumerable.

MDN documentation

pub fn to_locale_string(&self) -> JsString[src]

This is supported on feature="ext" only.

The toLocaleString() method returns a string representing the object. This method is meant to be overridden by derived objects for locale-specific purposes.

MDN documentation

pub fn to_string(&self) -> JsString[src]

This is supported on feature="ext" only.

The toString() method returns a string representing the object.

MDN documentation

pub fn value_of(&self) -> Object[src]

This is supported on feature="ext" only.

The valueOf() method returns the primitive value of the specified object.

MDN documentation

Trait Implementations

impl<T: JsCast> AsRef<JsValue> for ReadOnlyArray<T>[src]

impl<T: JsCast> AsRef<Object> for ReadOnlyArray<T>[src]

impl<T: JsCast> AsRef<ReadOnlyArray<T>> for ReadOnlyArray<T>[src]

impl<T: JsCast> Clone for ReadOnlyArray<T>[src]

impl<T: JsCast> Debug for ReadOnlyArray<T>[src]

impl<T: JsCast> Deref for ReadOnlyArray<T>[src]

type Target = Object

The resulting type after dereferencing.

impl<T: Eq + JsCast> Eq for ReadOnlyArray<T>[src]

impl<T: JsCast> From<Array> for ReadOnlyArray<T>[src]

impl<T: JsCast> From<JsValue> for ReadOnlyArray<T>[src]

impl<T: JsCast> From<ReadOnlyArray<T>> for JsValue[src]

impl<T: JsCast> From<ReadOnlyArray<T>> for Object[src]

impl<T: JsCast> FromWasmAbi for ReadOnlyArray<T>[src]

type Abi = <Array as FromWasmAbi>::Abi

The wasm ABI type that this converts from when coming back out from the ABI boundary. Read more

impl<'a, T: JsCast> IntoWasmAbi for &'a ReadOnlyArray<T>[src]

type Abi = <&'a Array as IntoWasmAbi>::Abi

The wasm ABI type that this converts into when crossing the ABI boundary. Read more

impl<T: JsCast> JsCast for ReadOnlyArray<T>[src]

impl<T: JsCast> OptionFromWasmAbi for ReadOnlyArray<T>[src]

impl<'a, T: JsCast> OptionIntoWasmAbi for &'a ReadOnlyArray<T>[src]

impl<T: PartialEq + JsCast> PartialEq<ReadOnlyArray<T>> for ReadOnlyArray<T>[src]

impl<T: JsCast> RefFromWasmAbi for ReadOnlyArray<T>[src]

type Abi = <Array as RefFromWasmAbi>::Abi

The wasm ABI type references to Self are recovered from.

type Anchor = ManuallyDrop<Self>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don't persist beyond one function call, and so that they remain anonymous. Read more

impl<T: JsCast> StructuralEq for ReadOnlyArray<T>[src]

impl<T: JsCast> StructuralPartialEq for ReadOnlyArray<T>[src]

impl<T: JsCast> WasmDescribe for ReadOnlyArray<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for ReadOnlyArray<T> where
    T: RefUnwindSafe

impl<T> !Send for ReadOnlyArray<T>

impl<T> !Sync for ReadOnlyArray<T>

impl<T> Unpin for ReadOnlyArray<T> where
    T: Unpin

impl<T> UnwindSafe for ReadOnlyArray<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.