pub struct TextRef<'a> { /* private fields */ }Expand description
Read-only reference to a Text CRDT.
Text is a sequence CRDT optimized for collaborative text editing.
For large documents, prefer slice() or chars() over content() to avoid
allocating the entire string.
Implementations§
Source§impl<'a> TextRef<'a>
impl<'a> TextRef<'a>
Sourcepub fn content(&self) -> String
pub fn content(&self) -> String
Get the full text content as a String.
For large documents, consider using slice() or chars() instead
to avoid allocating the entire string.
Sourcepub fn slice(&self, range: Range<usize>) -> String
pub fn slice(&self, range: Range<usize>) -> String
Get a slice of the text as a String.
Range is in Unicode characters (not bytes). This is more efficient than
content() for extracting portions of large documents.
§Example
use diamond_types_extended::{Document, Uuid};
let mut doc = Document::new();
let alice = doc.create_agent(Uuid::from_u128(0xA11CE));
doc.transact(alice, |tx| {
let id = tx.root().create_text("content");
tx.text_by_id(id).unwrap().insert(0, "Hello, world!");
});
let text = doc.root().get_text("content").unwrap();
assert_eq!(text.slice(0..5), "Hello");
assert_eq!(text.slice(7..12), "world");Auto Trait Implementations§
impl<'a> Freeze for TextRef<'a>
impl<'a> RefUnwindSafe for TextRef<'a>
impl<'a> Send for TextRef<'a>
impl<'a> Sync for TextRef<'a>
impl<'a> Unpin for TextRef<'a>
impl<'a> UnsafeUnpin for TextRef<'a>
impl<'a> UnwindSafe for TextRef<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more