Typed structs for Loro CRDTs
rust
crdt
1# loroscope
2
3Typed structs for [Loro](https://loro.dev/) CRDTs.
4
5[Loro](https://loro.dev/) is a CRDT library — it gives you conflict-free
6replicated containers (lists, maps, trees, rich text, etc.) with undo/redo,
7sync, and time travel. But working with it directly means string-keyed
8container lookups and manual `LoroValue` matching.
9
10`#[loroscope]` generates typed accessors from a struct definition, so field
11access is checked at compile time.
12
13## Example
14
15```rust
16use loroscope::loroscope;
17
18#[loroscope]
19struct TodoItem {
20 title: Text,
21 done: bool,
22}
23
24#[loroscope]
25struct App {
26 todos: List<TodoItem>,
27}
28
29let app = App::new();
30
31let item = app.todos().push_new();
32item.title().insert(0, "Buy milk").unwrap();
33item.set_done(false);
34
35assert_eq!(app.todos().len(), 1);
36assert!(!app.todos().get(0).unwrap().done());
37
38// The underlying LoroDoc is always available for export, import,
39// undo, subscriptions, etc.
40let _doc = app.doc();
41```
42
43## Field types
44
45| Type | Accessor |
46|---|---|
47| `f64`, `i64`, `bool`, `String` | Getter + `set_` setter |
48| [`Text`], [`Counter`] | Getter returning the container |
49| [`List<T>`], [`Map<V>`], [`MovableList<T>`], [`Tree<T>`] | Getter returning a typed collection |
50| `LoroList`, `LoroMap`, `LoroText`, ... | Getter returning the raw Loro container |
51| Any `#[loroscope]` struct | Getter returning a nested typed view |
52
53[`Text`]: https://docs.rs/loroscope/latest/loroscope/type.Text.html
54[`Counter`]: https://docs.rs/loroscope/latest/loroscope/type.Counter.html
55[`List<T>`]: https://docs.rs/loroscope/latest/loroscope/struct.List.html
56[`Map<V>`]: https://docs.rs/loroscope/latest/loroscope/struct.Map.html
57[`MovableList<T>`]: https://docs.rs/loroscope/latest/loroscope/struct.MovableList.html
58[`Tree<T>`]: https://docs.rs/loroscope/latest/loroscope/struct.Tree.html