Struct ywasm::YArray[][src]

pub struct YArray(_);
Expand description

A collection used to store data in an indexed sequence structure. This type is internally implemented as a double linked list, which may squash values inserted directly one after another into single list node upon transaction commit.

Reading a root-level type as an YArray means treating its sequence components as a list, where every countable element becomes an individual entity:

  • JSON-like primitives (booleans, numbers, strings, JSON maps, arrays etc.) are counted individually.
  • Text chunks inserted by Text data structure: each character becomes an element of an array.
  • Embedded and binary values: they count as a single element even though they correspond of multiple bytes.

Like all Yrs shared data types, YArray is resistant to the problem of interleaving (situation when elements inserted one after another may interleave with other peers concurrent inserts after merging all updates together). In case of Yrs conflict resolution is solved by using unique document id to determine correct and consistent ordering.

Implementations

Creates a new preliminary instance of a YArray shared data type, with its state initialized to provided parameter.

Preliminary instances can be nested into other shared data types such as YArray and YMap. Once a preliminary instance has been inserted this way, it becomes integrated into ywasm document store and cannot be nested again: attempt to do so will result in an exception.

Returns true if this is a preliminary instance of YArray.

Preliminary instances can be nested into other shared data types such as YArray and YMap. Once a preliminary instance has been inserted this way, it becomes integrated into ywasm document store and cannot be nested again: attempt to do so will result in an exception.

Returns a number of elements stored within this instance of YArray.

Converts an underlying contents of this YArray instance into their JSON representation.

Inserts a given range of items into this YArray instance, starting at given index.

Appends a range of items at the end of this YArray instance.

Deletes a range of items of given length from current YArray instance, starting from given index.

Returns an element stored under given index.

Returns an iterator that can be used to traverse over the values stored withing this instance of YArray.

Example:

import YDoc from 'ywasm'

/// document on machine A
const doc = new YDoc()
const array = doc.getArray('name')
const txn = doc.beginTransaction()
try {
    array.push(txn, ['hello', 'world'])
    for (let item of array.values(txn)) {
        console.log(item)
    }
} finally {
    txn.free()
}

Trait Implementations

Performs the conversion.

Performs the conversion.

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

Recover a Self from Self::Abi. Read more

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

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary. Read more

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi. Read more

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more

The wasm ABI type references to Self are recovered from.

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

Recover a Self::Anchor from Self::Abi. Read more

Same as RefFromWasmAbi::Abi

Same as RefFromWasmAbi::Anchor

Same as RefFromWasmAbi::ref_from_abi

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Same as IntoWasmAbi::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.