pub struct DocumentBuilder { /* private fields */ }Expand description
Builder for a Document with a path and/or initial content.
Content precedence: a buffer from Self::with_buffer wins over text
from Self::with_text; with neither, the document is empty. Nothing
here touches the filesystem — Document::open reads, the builder only
assembles. Every built document gets a fresh [DocumentId], starts at
version 0, and is clean.
§Examples
use lattice_core::DocumentBuilder;
let doc = DocumentBuilder::default()
.with_path("/tmp/notes.txt")
.with_text("draft\n")
.build();
assert_eq!(doc.text(), "draft\n");
assert_eq!(doc.path().and_then(|p| p.to_str()), Some("/tmp/notes.txt"));
assert!(!doc.dirty());Implementations§
Source§impl DocumentBuilder
impl DocumentBuilder
Sourcepub fn with_path(self, path: impl Into<PathBuf>) -> Self
pub fn with_path(self, path: impl Into<PathBuf>) -> Self
Set the file path the document will report and Document::save
will write to. Not checked for existence.
Sourcepub fn with_text(self, text: impl Into<String>) -> Self
pub fn with_text(self, text: impl Into<String>) -> Self
Set the initial text. Ignored if Self::with_buffer is also set.
Sourcepub fn with_buffer(self, buffer: Buffer) -> Self
pub fn with_buffer(self, buffer: Buffer) -> Self
Build the Document around a
pre-existing Buffer instead of going through a String.
Used by callers that already hold a Buffer (typically from
DocumentSnapshot.buffer.clone() — Buffer::clone is
Rope::clone which is Arc-backed and O(1)) and want to
avoid the Buffer → as_string() → from_text(&str) round-
trip. K.4.11’s MultibufferDocumentHandle::dispatch_with_cancel
is the primary consumer: every multibuffer keystroke ran
the round-trip, allocating O(composed_size) bytes on the
App thread per motion. After this fix the per-keystroke
cost is one Arc bump.
Slice: K.4.11.perf-fix (2026-06-02).