loro

Crates.ioloro
lib.rsloro
version1.8.1
created_at2022-08-07 12:29:50.518504+00
updated_at2025-09-23 13:32:43.23024+00
descriptionLoro is a high-performance CRDTs framework. Make your app collaborative efforlessly.
homepagehttps://loro.dev
repositoryhttps://github.com/loro-dev/loro/
max_upload_size
id640197
size436,987
Leon Zhao (Leeeon233)

documentation

https://docs.rs/loro/

README

Loro

Loro is a high‑performance CRDT framework for local‑first apps that keeps state consistent across devices and users, works offline and in real time, automatically merges conflicts, and enables undo/redo and time travel.

Loro is a high-performance CRDTs library offering Rust, JavaScript and Swift APIs.

Common Tasks & Examples

Getting Started

Real-time Collaboration

Rich Text Editing

Data Structures

Ephemeral State & Presence

  • Not currently provided in the Rust crate. Model presence in your app layer alongside CRDT updates (e.g., via your network transport). Cursors can be shared using get_cursor data if needed.

Version Control & History

Performance & Storage

Documentation

  • Start with the Rust API docs for LoroDoc (container management, versioning, import/export, events) That page hosts examples and details for most important methods you’ll use day-to-day.
  • Loro Website for more details and guides
  • Loro Examples for more examples and guides

Getting Started

Add to your Cargo.toml:

[dependencies]
loro = "^1"

LoroDoc quick tour

Optional cargo features:

[dependencies]
loro = { version = "^1", features = ["jsonpath"] }

Quick Examples

  1. Local edits, change events, and two-peer sync
use loro::{LoroDoc, ExportMode};
use std::sync::Arc;

let a = LoroDoc::new();
let b = LoroDoc::new();

// Listen for container diffs on `a`
let _changes = a.subscribe_root(Arc::new(|e| {
    println!("changed containers: {}", e.events.len());
}));

a.get_text("text").insert(0, "Hello, Loro!").unwrap();
a.commit(); // events fire on commit/export/import/checkout

// Sync via export/import (send `updates` via your transport)
let updates = a.export(ExportMode::all_updates()).unwrap();
b.import(&updates).unwrap();

assert_eq!(a.get_deep_value(), b.get_deep_value());
  1. Time travel and revert
use loro::LoroDoc;

let doc = LoroDoc::new();
let text = doc.get_text("text");
text.insert(0, "Hello").unwrap();
let v0 = doc.state_frontiers();

text.insert(5, ", world").unwrap();
assert_eq!(text.to_string(), "Hello, world");

// Time travel to v0 (read-only)
doc.checkout(&v0).unwrap();
assert_eq!(text.to_string(), "Hello");

// Return to latest and revert
doc.checkout_to_latest();
doc.revert_to(&v0).unwrap();
assert_eq!(text.to_string(), "Hello");
Commit count: 1969

cargo fmt