pub struct DocumentWriter<'a> { /* private fields */ }Expand description
Closure-free mutation handle for FFI/WASM consumers.
Binds an agent to a document so mutations don’t need closures.
Each method executes a single operation via transact() internally.
For batching multiple operations in Rust, prefer Document::transact().
Path-based methods return bool (true = success) or Option<CrdtId>
so FFI consumers can detect invalid paths without panicking.
§Example
use diamond_types_extended::{Document, Uuid};
let mut doc = Document::new();
let alice = doc.create_agent(Uuid::from_u128(0xA11CE));
{
let mut w = doc.writer(alice);
w.root_set("title", "My Document");
w.root_set("count", 42);
let text_id = w.root_create_text("body");
assert!(w.text_push(&["body"], "Hello, world!"));
assert!(!w.text_push(&["nonexistent"], "oops"));
}
assert_eq!(doc.root().get("title").unwrap().as_str(), Some("My Document"));
assert_eq!(doc.root().get_text("body").unwrap().content(), "Hello, world!");Implementations§
Source§impl<'a> DocumentWriter<'a>
impl<'a> DocumentWriter<'a>
Sourcepub fn set(
&mut self,
path: &[&str],
key: &str,
value: impl Into<PrimitiveValue>,
) -> bool
pub fn set( &mut self, path: &[&str], key: &str, value: impl Into<PrimitiveValue>, ) -> bool
Set a key to a primitive value in a map at path.
Path points to the containing map. Empty path = root (always succeeds).
Returns false if the path doesn’t resolve to a map.
Sourcepub fn set_nil(&mut self, path: &[&str], key: &str) -> bool
pub fn set_nil(&mut self, path: &[&str], key: &str) -> bool
Set a key to nil in a map at path.
Returns false if the path doesn’t resolve to a map.
Sourcepub fn create_map(&mut self, path: &[&str], key: &str) -> Option<CrdtId>
pub fn create_map(&mut self, path: &[&str], key: &str) -> Option<CrdtId>
Create a nested Map at key in a map at path.
Returns None if the path doesn’t resolve to a map.
Sourcepub fn create_text(&mut self, path: &[&str], key: &str) -> Option<CrdtId>
pub fn create_text(&mut self, path: &[&str], key: &str) -> Option<CrdtId>
Create a nested Text CRDT at key in a map at path.
Returns None if the path doesn’t resolve to a map.
Sourcepub fn create_set(&mut self, path: &[&str], key: &str) -> Option<CrdtId>
pub fn create_set(&mut self, path: &[&str], key: &str) -> Option<CrdtId>
Create a nested Set CRDT at key in a map at path.
Returns None if the path doesn’t resolve to a map.
Sourcepub fn create_register(&mut self, path: &[&str], key: &str) -> Option<CrdtId>
pub fn create_register(&mut self, path: &[&str], key: &str) -> Option<CrdtId>
Create a nested Register CRDT at key in a map at path.
Returns None if the path doesn’t resolve to a map.
Sourcepub fn root_set(&mut self, key: &str, value: impl Into<PrimitiveValue>)
pub fn root_set(&mut self, key: &str, value: impl Into<PrimitiveValue>)
Set a key to a primitive value in the root map.
Sourcepub fn root_create_map(&mut self, key: &str) -> CrdtId
pub fn root_create_map(&mut self, key: &str) -> CrdtId
Create a nested Map in the root map.
Sourcepub fn root_create_text(&mut self, key: &str) -> CrdtId
pub fn root_create_text(&mut self, key: &str) -> CrdtId
Create a nested Text CRDT in the root map.
Sourcepub fn root_create_set(&mut self, key: &str) -> CrdtId
pub fn root_create_set(&mut self, key: &str) -> CrdtId
Create a nested Set CRDT in the root map.
Sourcepub fn text_insert(&mut self, path: &[&str], pos: usize, content: &str) -> bool
pub fn text_insert(&mut self, path: &[&str], pos: usize, content: &str) -> bool
Insert text at a position in a Text CRDT at path.
Returns false if the path doesn’t resolve to a Text CRDT.
Sourcepub fn text_delete(&mut self, path: &[&str], range: Range<usize>) -> bool
pub fn text_delete(&mut self, path: &[&str], range: Range<usize>) -> bool
Delete a range of text in a Text CRDT at path.
Returns false if the path doesn’t resolve to a Text CRDT.
Sourcepub fn text_push(&mut self, path: &[&str], content: &str) -> bool
pub fn text_push(&mut self, path: &[&str], content: &str) -> bool
Append text to the end of a Text CRDT at path.
Returns false if the path doesn’t resolve to a Text CRDT.
Sourcepub fn set_add(
&mut self,
path: &[&str],
value: impl Into<PrimitiveValue>,
) -> bool
pub fn set_add( &mut self, path: &[&str], value: impl Into<PrimitiveValue>, ) -> bool
Add a value to a Set CRDT at path.
Returns false if the path doesn’t resolve to a Set CRDT.
Sourcepub fn set_remove(
&mut self,
path: &[&str],
value: impl Into<PrimitiveValue>,
) -> bool
pub fn set_remove( &mut self, path: &[&str], value: impl Into<PrimitiveValue>, ) -> bool
Remove a value from a Set CRDT at path.
Returns false if the path doesn’t resolve to a Set CRDT.