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>
impl<T> LargeVec<T>
Sourcepub fn try_into_vec(self) -> Result<Vec<T>, Self>
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.
Trait Implementations§
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.
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§impl<T> FromWasmAbi for LargeVec<T>where
T: Tsify + DeserializeOwned + 'static,
T::JsType: WasmDescribeVector,
impl<T> FromWasmAbi for LargeVec<T>where
T: Tsify + DeserializeOwned + 'static,
T::JsType: WasmDescribeVector,
Source§unsafe fn from_abi(js: Self::Abi) -> Self
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§impl<T> IntoIterator for LargeVec<T>
impl<T> IntoIterator for LargeVec<T>
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.
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.