Typed structs for Loro CRDTs
rust crdt

loroscope#

Typed structs for Loro CRDTs.

Loro is a CRDT library — it gives you conflict-free replicated containers (lists, maps, trees, rich text, etc.) with undo/redo, sync, and time travel. But working with it directly means string-keyed container lookups and manual LoroValue matching.

#[loroscope] generates typed accessors from a struct definition, so field access is checked at compile time.

Example#

use loroscope::loroscope;

#[loroscope]
struct TodoItem {
    title: Text,
    done: bool,
}

#[loroscope]
struct App {
    todos: List<TodoItem>,
}

let app = App::new();

let item = app.todos().push_new();
item.title().insert(0, "Buy milk").unwrap();
item.set_done(false);

assert_eq!(app.todos().len(), 1);
assert!(!app.todos().get(0).unwrap().done());

// The underlying LoroDoc is always available for export, import,
// undo, subscriptions, etc.
let _doc = app.doc();

Field types#

Type Accessor
f64, i64, bool, String Getter + set_ setter
Text, Counter Getter returning the container
List<T>, Map<V>, MovableList<T>, Tree<T> Getter returning a typed collection
LoroList, LoroMap, LoroText, ... Getter returning the raw Loro container
Any #[loroscope] struct Getter returning a nested typed view