Skip to main content

synckit_core/
lib.rs

1//! SyncKit Core - High-performance sync engine
2//!
3//! This is the Rust core of SyncKit, compiled to both native and WASM.
4//! It implements:
5//! - Document structure with field-level LWW
6//! - Vector clocks for causality tracking
7//! - CRDT data structures (OR-Set, PN-Counter, Text)
8//! - Binary protocol encoding/decoding (when prost feature enabled)
9//!
10//! # Examples
11//!
12//! ```rust
13//! use synckit_core::{Document, ClientID, VectorClock};
14//!
15//! let mut doc = Document::new("doc-123".to_string());
16//! doc.set_field(
17//!     "title".to_string(),
18//!     serde_json::json!("Hello World"),
19//!     1,
20//!     "client-1".to_string()
21//! );
22//! ```
23
24// Use wee_alloc when building for WASM with core-lite feature (size optimization)
25#[cfg(all(target_arch = "wasm32", feature = "wee_alloc"))]
26#[global_allocator]
27static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
28
29pub mod awareness;
30pub mod document;
31pub mod error;
32pub mod storage;
33pub mod sync;
34
35// Protocol module only included if prost feature is enabled
36#[cfg(feature = "prost")]
37pub mod protocol;
38
39// CRDTs are feature-gated (only compile if needed)
40#[cfg(any(
41    feature = "text-crdt",
42    feature = "counters",
43    feature = "sets",
44    feature = "fractional-index"
45))]
46pub mod crdt;
47
48#[cfg(feature = "wasm")]
49pub mod wasm;
50
51// Re-exports for convenience
52pub use awareness::{Awareness, AwarenessState, AwarenessUpdate};
53pub use document::Document;
54pub use error::{Result, SyncError};
55pub use sync::{Timestamp, VectorClock};
56
57/// Client identifier type
58pub type ClientID = String;
59
60/// Document identifier type  
61pub type DocumentID = String;
62
63/// Field path within a document
64pub type FieldPath = String;
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_basic_import() {
72        // Smoke test that modules compile
73        let _client_id: ClientID = "test-client".to_string();
74    }
75}