|
| 1 | +# Array |
| 2 | + |
| 3 | +Opaque container for `Value::Array`'s ordered element storage, enabling |
| 4 | +alternative backends without call-site changes. It follows the same |
| 5 | +abstraction pattern as [`Object`](object.md) and [`Set`](set.md). |
| 6 | + |
| 7 | +## Design |
| 8 | + |
| 9 | +`Array` wraps a `Vec<Value>` today but exposes only a curated method surface |
| 10 | +(`get`, `get_mut`, `first`, `last`, `contains`, `iter`, `iter_mut`, `push`, |
| 11 | +`append`, `extend`, `extend_from_slice`, `retain`, `clear`, `reverse`, `sort`, |
| 12 | +`cursor`, and serde). The inner vector is private, and `Array` does not |
| 13 | +implement `Deref`, so callers cannot depend on the backing representation. |
| 14 | + |
| 15 | +Indexing uses `Index<usize>` and returns `Value::Undefined` for an out-of-range |
| 16 | +index, matching `Value` indexing semantics. Use `get` when distinguishing a |
| 17 | +missing element from an element whose value is explicitly `Undefined`. |
| 18 | + |
| 19 | +Iteration follows sequence order. The opaque cursor supports incremental |
| 20 | +traversal needed by RVM iteration state without exposing iterator internals. |
| 21 | +`Ord` is implemented against the sequence iterator so alternative backends can |
| 22 | +preserve the current array comparison behavior. |
| 23 | + |
| 24 | +## Scenarios enabled |
| 25 | + |
| 26 | +- **Inline-small storage** — store short arrays inline and spill to the heap |
| 27 | + only for larger values. |
| 28 | +- **Lazy/streaming storage** — materialize elements from JSON, CBOR, or a host |
| 29 | + provider on demand. |
| 30 | +- **Arena allocation** — use bump allocation for evaluation-time temporaries |
| 31 | + and release them together at query end. |
| 32 | +- **FFI-backed storage** — access host-language lists or arrays without |
| 33 | + copying at every binding boundary. |
0 commit comments