lorosurgeon
Derive macros for bidirectional serialization between Rust types and Loro CRDT containers — the Loro equivalent of autosurgeon for Automerge.
#[derive(Hydrate, Reconcile)] generates field-level mapping between Rust types and Loro containers. Only modified fields produce CRDT operations.
Quick Start
use LoroDoc;
use ;
let doc = new;
let config = Config ;
config.to_doc.unwrap; // Rust → Loro
doc.commit;
let loaded = from_doc.unwrap; // Loro → Rust
assert_eq!;
Documentation
Full API documentation on docs.rs →
The crate docs include type mapping tables, attribute reference, examples for concurrent editing, custom serialization, flatten, keyed list diffing, and more.
Features
- Structs →
LoroMap(fields become keys) - Enums →
LoroMapwith variant discriminator, unit variants as strings Vec<T>→LoroListwith Myers LCS diffing#[loro(movable)]→LoroMovableListwith identity-preservingmov()/set()HashMap<String, V>→LoroMapwith stale-key cleanup#[loro(text)]→LoroTextwith character-level diffing (onStringfields)- No-op detection — identical values produce zero CRDT operations
- Concurrent merge — field-level granularity means independent edits compose
Attributes
// Container-level
// DocSync: to_doc() / from_doc()
// Field-level
// Identity key for movable list diffing
// Different key in Loro
// serde_json round-trip
// LoroText with character-level LCS
// LoroMovableList instead of LoroList
// Default::default() when absent
// Custom default function
// Inline nested struct fields
// Custom hydrate + reconcile
// Custom hydrate only
// Custom reconcile only
License
MIT