Skip to main content

LargeVec

Struct LargeVec 

Source
pub struct LargeVec<T>(Items<T>);
Expand description

A list parameter that converts a JavaScript array lazily, one item at a time. Use it for lists that can be large, such as a vault’s ciphers, and a plain Vec for the rest.

A regular Vec<T> converts the whole array as soon as JavaScript passes it in, which grows WASM linear memory. WASM cannot give that memory back, so the allocation stays for the rest of the session.

TypeScript sees LargeVec<T> as T[], so Vec and LargeVec are interchangeable from TypeScript’s perspective. Rust and UniFFI callers wrap a regular Vec with .into(), which does not copy it. Read the items by iterating over them, or take the Rust Vec back with LargeVec::try_into_vec.

Tuple Fields§

§0: Items<T>

Implementations§

Source§

impl<T> LargeVec<T>

Source

pub fn len(&self) -> usize

The number of items.

Source

pub fn is_empty(&self) -> bool

Whether the list has no items.

Source

pub fn try_into_vec(self) -> Result<Vec<T>, Self>

The items as a Vec, when they came from Rust or UniFFI as one, or the list itself when they come from JavaScript.

A Vec is already in memory, so a function can use it as a slice, which avoids moving each item out as iterating over the list does. Items from JavaScript are not converted yet, so for those the function iterates over the returned list.

Source§

impl<T: 'static> LargeVec<T>

Source

pub fn map<U: 'static>( self, f: impl Fn(T) -> U + Send + Sync + 'static, ) -> LargeVec<U>

Applies f to each item: right away for items from Rust, and as each item is read for items from JavaScript.

Trait Implementations§

Source§

impl<T> From<Vec<T>> for LargeVec<T>

Source§

fn from(items: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> FromWasm for LargeVec<T>
where T: Tsify + DeserializeOwned + 'static, T::JsType: WasmDescribeVector,

Crosses as itself: the items convert when they are read, so there is nothing to convert at the boundary.

Source§

type Wire = LargeVec<T>

The type JavaScript actually passes.
Source§

fn from_wire(wire: Self) -> Result<Self, WireError>

Recovers the Rust value from the wire value.
Source§

impl<T> FromWasmAbi for LargeVec<T>
where T: Tsify + DeserializeOwned + 'static, T::JsType: WasmDescribeVector,

Source§

unsafe fn from_abi(js: Self::Abi) -> Self

Takes the array as one JavaScript value handle per item, four bytes each, and converts the items only when they are read.

The generated JavaScript copies the handles when the call is made, as for a Vec<JsValue>, so changes the caller makes to the array after the call do not reach the items, which an async function reads later.

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

impl<T> IntoIterator for LargeVec<T>

Source§

type Item = Result<T, LargeVecError>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

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

fn into_iter(self) -> IntoIter<T> ⓘ

Creates an iterator from a value. Read more
Source§

impl<T> WasmDescribe for LargeVec<T>
where T: Tsify, T::JsType: WasmDescribeVector,

Described as a Vec of the item’s JavaScript type, so wasm_bindgen types the parameter T[] and generates the same JavaScript as for a Vec<T>. That type is a JsCast type, whose vector crosses as a list of value handles, the ABI from_abi takes over. Bounding on it, not on T itself, rules out a T such as u8 whose vector crosses as raw bytes.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for LargeVec<T>

§

impl<T> !UnwindSafe for LargeVec<T>

§

impl<T> Freeze for LargeVec<T>
where Items<T>: Freeze,

§

impl<T> Send for LargeVec<T>
where Items<T>: Send,

§

impl<T> Sync for LargeVec<T>
where Items<T>: Sync,

§

impl<T> Unpin for LargeVec<T>
where Items<T>: Unpin,

§

impl<T> UnsafeUnpin for LargeVec<T>
where Items<T>: UnsafeUnpin,

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> 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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more