| Crates.io | braid_rs |
| lib.rs | braid_rs |
| version | 0.1.2 |
| created_at | 2026-01-21 00:12:27.90535+00 |
| updated_at | 2026-01-22 15:38:16.407566+00 |
| description | Unified Braid Protocol implementation in Rust, including Braid-HTTP, Antimatter CRDT, and BraidFS. |
| homepage | |
| repository | https://github.com/braid-org/braid-rs |
| max_upload_size | |
| id | 2057883 |
| size | 2,059,730 |
A unified Rust implementation of the Braid Protocol for building decentralized, synchronized web applications.
| Feature | Description |
|---|---|
| Core Braid-HTTP | Pure Braid implementation with HTTP 209 subscriptions |
| Antimatter CRDT | JS-compatible CRDT with history compression |
| MergeType System | Pluggable merge algorithms (Sync9, Antimatter, Diamond) |
| Braid-Blob | Content-addressable storage with SHA-256 hashing |
| BraidFS | Filesystem sync daemon with .braidignore support |
[dependencies]
braid_rs = "0.1.0"
use braid_rs::core::client::BraidClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = BraidClient::new();
// Simple GET request
let response = client.get("http://braid.org/resource").await?;
println!("Content: {:?}", response.body());
// Subscribe to updates
let mut subscription = client.subscribe("http://braid.org/resource").await?;
while let Some(update) = subscription.next().await {
println!("Update: version={:?}", update.version);
}
Ok(())
}
use braid_rs::antimatter::{AntimatterCrdt, PrunableCrdt};
use braid_rs::antimatter::messages::Patch;
use serde_json::json;
// Create CRDT with send callback
let mut crdt = AntimatterCrdt::new(
Some("peer1".to_string()),
MyCrdt::new(),
Box::new(|msg| { /* send to other peers */ }),
);
// Apply local edit
let version = crdt.update(vec![Patch {
range: "0:0".to_string(),
content: json!("Hello"),
}]);
// Get current state
println!("Content: {}", crdt.crdt.get_content());
println!("Version: {:?}", crdt.current_version);
// Prune history when acknowledged
crdt.prune(false);
use braid_rs::core::merge::{MergeType, MergeTypeRegistry, MergePatch};
use serde_json::json;
// Create registry with built-in types
let mut registry = MergeTypeRegistry::new();
// Get a merge type by name
let mut merge = registry.create("sync9", "peer1").unwrap();
// Initialize with content
merge.initialize("Hello World");
// Apply local edit
let patch = MergePatch::new("0:5", json!("Hi"));
let result = merge.local_edit(patch);
println!("New version: {:?}", result.version);
println!("Content: {}", merge.get_content());
use axum::{Router, routing::get};
use braid_rs::core::server::{BraidLayer, BraidState};
async fn handler() -> impl IntoResponse {
"Hello from Braid!"
}
let app = Router::new()
.route("/resource", get(handler))
.layer(BraidLayer::new().middleware());
braid_rs/
├── src/
│ ├── core/ # Braid-HTTP protocol
│ │ ├── client/ # HTTP client with subscriptions
│ │ ├── server/ # Axum middleware & handlers
│ │ ├── merge/ # MergeType trait & implementations
│ │ └── protocol/ # Protocol constants & types
│ │
│ ├── antimatter/ # Antimatter CRDT (JS-compatible)
│ │ ├── antimatter.rs # Main coordination layer
│ │ ├── sequence_crdt.rs # Text/array CRDT
│ │ ├── json_crdt.rs # Recursive JSON CRDT
│ │ └── messages.rs # Protocol messages
│ │
│ ├── blob/ # Content-addressable storage
│ │ ├── store.rs # SQLite metadata + FS storage
│ │ └── http.rs # Axum HTTP endpoints
│ │
│ └── fs/ # Filesystem sync daemon
│ ├── mod.rs # Daemon & file watching
│ └── config.rs # .braidignore, debouncing
Sync local files with a Braid server:
# Start the daemon
braidfs run
# Add a sync mapping
braidfs sync ./my-folder http://example.com/resource
Run a standalone blob server:
braid-blob serve --port 8080 --data ./data
Place a .braidignore file in synced directories:
# Ignore git files
.git
.git/**
# Ignore dependencies
node_modules/**
# Ignore temp files
*.swp
*.swo
*~
Location: ~/.braidfs/config
{
"port": 45678,
"debounce_ms": 100,
"sync": {
"./project": true
},
"ignore_patterns": [".git/**", "node_modules/**"]
}
This implementation follows draft-toomim-httpbis-braid-http-04:
| Header | Support |
|---|---|
Subscribe: true (HTTP 209) |
✅ |
Version |
✅ |
Parents |
✅ |
Merge-Type |
✅ |
Patches |
✅ |
Content-Range |
✅ |
Dual-licensed under Apache 2.0 or MIT at your option.